import { Injectable } from '@angular/core';
import { Result, ok, err } from '@shared/kernel/fp';
import { Session } from '../domain/session';

/** Infrastructure: talks to the (mock) DigiD identity provider. */
@Injectable({ providedIn: 'root' })
export class DigidAdapter {
  // ponytail: fake DigiD — any 9-digit BSN authenticates to a fixed identity.
  // Swap for a real OIDC redirect flow when there's a backend.
  async authenticate(bsn: string): Promise<Result<string, Session>> {
    const t = bsn.trim();
    if (!/^\d{9}$/.test(t)) return err($localize`:@@validation.bsn:Voer een geldig BSN van 9 cijfers in.`);
    return ok({ bsn: t, naam: 'Dr. A. (Anna) de Vries' });
  }
}
