import type { IValueObject } from '@gridpilot/shared/domain'; export interface PointsTableProps { pointsByPosition: Map; } export class PointsTable implements IValueObject { private readonly pointsByPosition: Map; constructor(pointsByPosition: Record | Map) { if (pointsByPosition instanceof Map) { this.pointsByPosition = new Map(pointsByPosition); } else { this.pointsByPosition = new Map( Object.entries(pointsByPosition).map(([key, value]) => [Number(key), value]), ); } } getPointsForPosition(position: number): number { if (!Number.isInteger(position) || position < 1) { return 0; } const value = this.pointsByPosition.get(position); return typeof value === 'number' ? value : 0; } get props(): PointsTableProps { return { pointsByPosition: new Map(this.pointsByPosition), }; } equals(other: IValueObject): boolean { const a = this.props.pointsByPosition; const b = other.props.pointsByPosition; if (a.size !== b.size) return false; for (const [key, value] of a.entries()) { if (b.get(key) !== value) { return false; } } return true; } }