import { describe, it, expect } from 'vitest';
import { parseBrpAddress } from './brp.adapter';

describe('parseBrpAddress (trust boundary)', () => {
  it('accepts a found address', () => {
    const r = parseBrpAddress({ gevonden: true, adres: { straat: 'Lange Voorhout 9', postcode: '2514 EA', woonplaats: 'Den Haag' } });
    expect(r.ok).toBe(true);
    if (r.ok) expect(r.value.adres?.postcode).toBe('2514 EA');
  });

  it('accepts "geen adres" (gevonden: false) as a valid outcome', () => {
    const r = parseBrpAddress({ gevonden: false });
    expect(r.ok).toBe(true);
  });

  it('rejects malformed responses', () => {
    expect(parseBrpAddress(null).ok).toBe(false);
    expect(parseBrpAddress({}).ok).toBe(false); // missing gevonden
    expect(parseBrpAddress({ gevonden: true }).ok).toBe(false); // found but no adres
    expect(parseBrpAddress({ gevonden: true, adres: { straat: 'x' } }).ok).toBe(false);
  });
});
