| 1 |
import { object, optional, type Validator } from "../lib/validation"; |
| 2 |
import { Amount } from "./amount"; |
| 3 |
import { Cost } from "./cost"; |
| 4 |
|
| 5 |
/** A position, a pair of units and cost. */ |
| 6 |
|
| 7 |
export class Position { |
| 8 |
constructor( |
| 9 |
readonly units: Amount, |
| 10 |
readonly cost: Cost | null, |
| 11 |
) {} |
| 12 |
|
| 13 |
private static raw_validator = object({ |
| 14 |
units: Amount.validator, |
| 15 |
cost: optional(Cost.validator), |
| 16 |
}); |
| 17 |
|
| 18 |
static validator: Validator<Position> = (json) => |
| 19 |
Position.raw_validator(json).map( |
| 20 |
({ units, cost }) => new Position(units, cost), |
| 21 |
); |
| 22 |
} |