import { describe, it, expect } from 'vitest';
import { Registration } from './registration';
import { isHerregistratieEligible, statusColor } from './registration.policy';

const reg = (status: Registration['status']): Registration => ({
  bigNummer: '19012345601',
  naam: 'Test',
  beroep: 'Arts',
  registratiedatum: '2012-09-01',
  geboortedatum: '1985-03-14',
  status,
});

describe('registration.policy', () => {
  it('only an active registration within the window is eligible', () => {
    const active = reg({ tag: 'Geregistreerd', herregistratieDatum: '2027-01-01' });
    expect(isHerregistratieEligible(active, new Date('2026-06-01'))).toBe(true); // within 12 months
    expect(isHerregistratieEligible(active, new Date('2020-01-01'))).toBe(false); // too early
  });

  it('struck-off / suspended registrations are never eligible', () => {
    expect(
      isHerregistratieEligible(
        reg({ tag: 'Doorgehaald', doorgehaaldOp: '2024-05-01', reden: 'x' }),
        new Date('2027-01-01'),
      ),
    ).toBe(false);
    expect(
      isHerregistratieEligible(
        reg({ tag: 'Geschorst', geschorstTot: '2026-12-31', reden: 'x' }),
        new Date('2027-01-01'),
      ),
    ).toBe(false);
  });

  it('statusColor is total over the union', () => {
    expect(statusColor('Geregistreerd')).toContain('groen');
    expect(statusColor('Doorgehaald')).toContain('rood');
    expect(statusColor('Geschorst')).toContain('oranje');
  });
});
