/**
 * Server-driven description of what a company still needs to finish onboarding.
 *
 * The portal renders this verbatim instead of deciding for itself which
 * documents apply or which fields are mandatory: the backend resolves the
 * nationality-based document set, checks which files are already uploaded, and
 * reports exactly what is outstanding. `isComplete` is the single source of
 * truth the wizard uses to auto-finish.
 */

export interface OnboardingInfoField {
  key: string;
  label: string;
}

export interface OnboardingDocumentField {
  fileKey: string;
  fileLabel: string;
  helpText: string | null;
  isRequired: boolean;
  isMultiple: boolean;
  maxFiles: number;
  allowedExtensions: string[];
  maxSizeMb: number;
  displayOrder: number;
  /** True when a file with this code is already stored for the company. */
  uploaded: boolean;
}

export interface OnboardingLicenseProfile {
  profileId: string;
  type: string;
  reference: string;
  /** True when at least one business-license file is stored on the profile. */
  uploaded: boolean;
}

export interface OnboardingPoaState {
  /** True when the company operates as a freight forwarder — PoA is mandatory. */
  required: boolean;
  /** True once any PoA detail has been entered. */
  provided: boolean;
  /** True when the delegation letter is stored for the company. */
  delegationLetterUploaded: boolean;
  /** PoA details still missing (only populated when `required`). */
  missingFields: OnboardingInfoField[];
  /** False while the PoA step still owes details or a delegation letter. */
  complete: boolean;
}

export class OnboardingRequirementsResponseDto {
  /** Resolved document setting code (by nationality) the docs were drawn from. */
  documentSettingCode: string;
  nationality: string;

  /** Required company-information fields and whether each is filled. */
  companyInfo: {
    complete: boolean;
    missingFields: OnboardingInfoField[];
  };

  /** The document fields the portal should render, with upload state. */
  documents: OnboardingDocumentField[];

  /** Per-operational-profile business-license requirements. */
  licenseProfiles: OnboardingLicenseProfile[];

  /** Power of Attorney state, so the wizard needn't re-derive the rule. */
  poa: OnboardingPoaState;

  /** Overall setup progress across fields + documents + licenses. */
  progress: { completed: number; total: number };

  /** True once every required field, document and license is satisfied. */
  isComplete: boolean;

  /** Whether the user has already submitted onboarding (awaiting approval). */
  onboardingCompleted: boolean;

  /** Human-readable list of everything still outstanding (empty when complete). */
  outstanding: string[];

  constructor(init: Omit<OnboardingRequirementsResponseDto, never>) {
    this.documentSettingCode = init.documentSettingCode;
    this.nationality = init.nationality;
    this.companyInfo = init.companyInfo;
    this.documents = init.documents;
    this.licenseProfiles = init.licenseProfiles;
    this.poa = init.poa;
    this.progress = init.progress;
    this.isComplete = init.isComplete;
    this.onboardingCompleted = init.onboardingCompleted;
    this.outstanding = init.outstanding;
  }
}
