import { BigProfile } from '@registratie/domain/big-profile';

const REDACTED = '‹redacted›';

/** Keep the last `keep` characters, mask the rest. */
function maskTail(value: string, keep: number): string {
  if (value.length <= keep) return '*'.repeat(value.length);
  return '*'.repeat(value.length - keep) + value.slice(-keep);
}

/** Redact a BSN for the dev state view: keep the last 3 digits, mask the rest. */
export function maskBsn(bsn: string): string {
  return maskTail(bsn, 3);
}

/**
 * Data minimisation for the dev "show the Model" panel: keep the structural /
 * decision-relevant fields (status, beroep, dates of registration) but redact
 * direct personal identifiers (name, address, date of birth) and mask the BIG
 * number. The panel is for inspecting state SHAPE, never for reading PII.
 */
export function redactProfile(p: BigProfile): unknown {
  return {
    registration: {
      bigNummer: maskTail(p.registration.bigNummer, 3),
      naam: REDACTED,
      beroep: p.registration.beroep,
      registratiedatum: p.registration.registratiedatum,
      geboortedatum: REDACTED,
      status: p.registration.status,
    },
    person: { naam: REDACTED, geboortedatum: REDACTED, adres: REDACTED },
  };
}
