/**
 * Nurse payout bank-account sub-domain (kept separate from the profile because
 * verification/payouts read it independently). Shapes mirror the b3 contract
 * (`dev/contracts/domains/identity-profiles.md` → `NurseBankAccountDto`). The full IBAN is
 * never returned — the DTO carries `ibanMasked` (last-4 only).
 */

/** `NurseBankAccountDto`. `matchedNationalId` is null until the ownership inquiry runs. */
export interface NurseBankAccountDto {
  id: number;
  bankName: string;
  /** Last-4 only, e.g. `••••3456`. */
  ibanMasked: string;
  isPrimary: boolean;
  isVerified: boolean;
  matchedNationalId: boolean | null;
}

/** The form input — bankName is derived from the IBAN in the API impl (see iban.ts). */
export interface AddBankAccountInput {
  iban: string;
  accountHolderName: string;
}

/**
 * The three ownership-inquiry UI states. `matchedNationalId` is the gating field:
 * null → pending, false → mismatch, true → verified (the b13 first-payout gate).
 */
export type BankAccountStatus = 'pending' | 'verified' | 'mismatch';

export function deriveBankStatus(account: Pick<NurseBankAccountDto, 'matchedNationalId'>): BankAccountStatus {
  if (account.matchedNationalId == null) return 'pending';
  return account.matchedNationalId ? 'verified' : 'mismatch';
}

/** The domain's API seam — a mock and the real client both implement this interface. */
export interface NurseBankAccountsApi {
  list(): Promise<NurseBankAccountDto[]>;
  add(input: AddBankAccountInput): Promise<NurseBankAccountDto>;
  setPrimary(id: number): Promise<void>;
  verifyOwnership(id: number): Promise<NurseBankAccountDto>;
}
