import { Brand, Result, ok, err } from '@shared/kernel/fp';

/** Value object: a non-negative whole number of hours. */
export type Uren = Brand<number, 'Uren'>;

export function parseUren(raw: string): Result<string, Uren> {
  const t = raw.trim();
  const n = Number(t);
  // Number('') is 0 — guard the empty string explicitly.
  if (t === '' || !Number.isInteger(n) || n < 0) {
    return err($localize`:@@validation.uren:Vul een geheel aantal in (0 of meer).`);
  }
  return ok(n as Uren);
}
