Begin defining a TaxReturn and Person model.
[ustaxlib.git] / src / TaxReturn.ts
1 import Form from './Form';
2 import { Person, Relation } from './Person';
3
4 export default class TaxReturn {
5 private _year: number;
6 private _people: Person[] = [];
7 private _forms: Form[] = [];
8
9 constructor(year: number) {
10 this._year = year;
11 }
12
13 get year(): number {
14 return this._year;
15 }
16
17 addPerson(person: Person) {
18 if (person.relation == Relation.Dependent) {
19 throw new UnsupportedFeatureError('Dependents are not supported');
20 }
21 if (person.relation == Relation.Self || person.relation == Relation.Spouse) {
22 const others = this._people.filter(p => p.relation == person.relation);
23 if (others.length > 0) {
24 throw new InconsistencyError('Cannot have more than one Self or Spouse');
25 }
26 }
27 this._people.push(person);
28 }
29
30 getPerson(name: RegExp | string): Person {
31 const people = this._people.filter(p => p.name.search(name) !== -1);
32 if (people.length != 1) {
33 throw new Error(`Person ${name} not found or too imprecise`);
34 }
35 return people[0];
36 }
37
38 addForm(form: Form) {
39 }
40 };
41
42 export class InconsistencyError extends Error {
43 };
44
45 export class UnsupportedFeatureError extends Error {
46 };