// ─── Enums ─────────────────────────────────────────────────────────────────
export type InquiryType = "SURVEILLANCE" | "RE_CERTIFICATION" | "INITIAL";

export type InquiryStatus =
  | "PENDING"
  | "IN_REVIEW"
  | "DRAFT_READY"
  | "CHANGES_REQUESTED"
  | "CLIENT_CONFIRMED"
  | "FINAL_ISSUED";

// ✅ NEW — Document attachment shape (matches backend InquiryDocument)
export type InquiryDocumentType =
  | "trade_license"
  | "previous_certificate"
  | "audit_report"
  | "scope_letter"
  | "other";

export interface InquiryDocument {
  type: InquiryDocumentType;
  path: string;
  filename: string;
  uploaded_at: string;
  uploaded_by?: number;
}

// ─── Nested entities ────────────────────────────────────────────────────────
export interface InquiryCompany {
  id: number;
  company_code: string;
  name: string;
  address: string;
  city: string;
  contact_person: string;
  email: string;
  mobile: string;
  accreditation: string;
  scope_of_work: string;
  country: { id: number; name: string; code: string; flag_url: string } | null;
  standards: InquiryStandard[];
}

export interface InquiryStandard {
  id: number;
  name: string;
  title: string;
}

export interface InquiryUser {
  id: number;
  firstName: string;
  lastName: string;
  email: string;
}

// ─── Main entity ────────────────────────────────────────────────────────────
export interface Inquiry {
  id: number;
  inquiry_ref: string;
  inquiry_type: InquiryType;
  audit_date: string;
  auditor_name: string;
  previous_cert_no: string | null;
  notes: string | null;
  documents: InquiryDocument[];
  certificate_number: string | null;
  issue_date: string | null;
  expiry_date: string | null;
  accreditation_body: string | null;
  scope_of_work: string | null;
  draft_pdf_path: string | null;
  draft_docx_path: string | null;
  draft_generated_at?: string | Date | null; // ✅ NEW

  change_request_notes: string | null;
  status: InquiryStatus;
  company: InquiryCompany;
  standards: InquiryStandard[];
  submitted_by: InquiryUser | null;
  assigned_to: InquiryUser | null;
  created_at: string;
  updated_at: string;
}

// ─── DTOs ───────────────────────────────────────────────────────────────────
export interface CreateInquiryDto {
  inquiry_type: InquiryType;
  company_id: number;
  audit_date: string;
  auditor_name: string;
  previous_cert_no?: string;
  notes?: string;
  submitted_by_id?: number;
  assigned_to_id?: number;
  standards?: number[];
  surveillance_audit_due?: string | null;
recertification_due?: string | null;
  
}

export interface UpdateInquiryDto {
  inquiry_type?: InquiryType;
  audit_date?: string;
  auditor_name?: string;
  previous_cert_no?: string;
  notes?: string;
  certificate_number?: string;
  issue_date?: string;
  expiry_date?: string;
  surveillance_audit_due?: string | null;   // ✅ ADD
  recertification_due?: string | null;      // ✅ ADD
  accreditation_body?: string;
  scope_of_work?: string;
  change_request_notes?: string;
  status?: InquiryStatus;
  standards?: number[];
  assigned_to_id?: number;
}

// ─── Pagination ─────────────────────────────────────────────────────────────
export interface PaginationMeta {
  total: number;
  page: number;
  limit: number;
  totalPages: number;
  hasNextPage: boolean;
  hasPrevPage: boolean;
}

export interface PaginatedInquiriesResponse {
  data: Inquiry[];
  meta: PaginationMeta;
}

// ─── Table row ──────────────────────────────────────────────────────────────
export interface InquiryRow {
  sno: number;
  id: number;
  inquiry_ref: string;
  inquiry_type: InquiryType;
  company_name: string;
  company_id: number;
  audit_date: string;
  auditor_name: string;
  previous_cert_no: string;
  certificate_number: string;
  issue_date: string;
  expiry_date: string;
  surveillance_audit_due?: string | null;
recertification_due?: string | null;
  scope_of_work: string;
  accreditation_body: string;
  status: InquiryStatus;
  standards: InquiryStandard[];
  submitted_by: InquiryUser | null;
  assigned_to: InquiryUser | null;
  draft_pdf_path: string | null;
  draft_docx_path: string | null;
  draft_generated_at: string | null; // ✅ NEW — for cache-busting download URLs
  change_request_notes: string | null;
  notes: string | null;
  // ... existing fields
  cert_body?: string | null;        // ✅ NEW
  audit_stage?: string | null;      // ✅ NEW
  documents: InquiryDocument[];
  created_at: string;
  updated_at: string;
  // full company for form hydration
  company: InquiryCompany;
  [key: string]: any;
}
