import type { SeafarerDepartment } from '../seafarer/seafarer.types';

/** Above/Below — the STCW limitation a Certificate of Competency is issued under. */
export type RankTier = 'ABOVE' | 'BELOW';

export type SeafarerRegistrationStatus =
  | 'DRAFT'
  // Filed, waiting on the counter-side biometric capture that produces the
  // BSID approval is blocked on.
  | 'AWAITING_BIOMETRICS'
  // BSID issued — the file is a reviewer's to decide.
  | 'UNDER_REVIEW'
  // Retained for registrations filed before biometrics moved ahead of review.
  | 'SUBMITTED'
  | 'RESUBMIT_REQUIRED'
  | 'APPROVED'
  | 'REJECTED';

export type Gender = 'MALE' | 'FEMALE';
export type MaritalStatus = 'SINGLE' | 'MARRIED' | 'DIVORCED' | 'WIDOWED';
export type HairColor = 'BLACK' | 'BROWN' | 'BLONDE' | 'RED' | 'GREY' | 'WHITE' | 'BALD' | 'OTHER';
export type EyeColor = 'BROWN' | 'BLACK' | 'BLUE' | 'GREEN' | 'HAZEL' | 'GREY' | 'OTHER';
export type BloodType =
  | 'A_POSITIVE' | 'A_NEGATIVE' | 'B_POSITIVE' | 'B_NEGATIVE'
  | 'AB_POSITIVE' | 'AB_NEGATIVE' | 'O_POSITIVE' | 'O_NEGATIVE' | 'UNKNOWN';

/** Every answer the registration collects — one typed row, no form schema. */
export interface SeafarerRegistrationAnswers {
  firstName: string | null;
  middleName: string | null;
  lastName: string | null;
  gender: Gender | null;
  dateOfBirth: string | null;
  maritalStatus: MaritalStatus | null;
  /** Full demonym as the profile stores it ("Ethiopian"). */
  nationality: string | null;
  nationalIdNumber: string | null;
  placeOfBirth: string | null;
  passportNumber: string | null;
  passportExpiry: string | null;
  department: SeafarerDepartment | null;
  /**
   * The STCW ship-size limitation this seafarer's CoCs are issued under.
   * Read with `department` to pick the CoC ladder; CoP carries no tier.
   */
  tier: RankTier | null;
  locationId: string | null;
  permanentAddress: string | null;
  currentAddress: string | null;
  emergencyContactName: string | null;
  emergencyContactRelationship: string | null;
  emergencyContactPhone: string | null;
  hairColor: HairColor | null;
  eyeColor: EyeColor | null;
  heightCm: number | null;
  weightKg: number | null;
  bloodType: BloodType | null;
  medicalCertificateNumber: string | null;
  medicalIssuerName: string | null;
  medicalIssueDate: string | null;
  declarationAccepted: boolean;
}

export interface SeafarerRegistration extends SeafarerRegistrationAnswers {
  id: string;
  registrationNumber: string;
  applicantUserId: string;
  profileId: string | null;
  status: SeafarerRegistrationStatus;
  submittedAt: string | null;
  decidedAt: string | null;
  decidedById: string | null;
  /** What the officer asked to be fixed, or noted at approval. */
  reviewRemark: string | null;
  rejectionReason: string | null;
  /** Stamped at approval. */
  seafarerNumber: string | null;
  createdAt: string;
  updatedAt: string;
}

/** `null` clears a field; an absent key leaves it alone. */
export type SaveSeafarerRegistration = Partial<SeafarerRegistrationAnswers>;

export interface SeafarerRegistrationIssue {
  kind: 'field' | 'document';
  target: string;
  message: string;
}
