// ─── Entities ─────────────────────────────────────────────────────────────────

export type JobStage    = "Stage 1" | "Stage 2";
export type MdRisk      = "Low" | "Medium" | "High";
export type ScheduleSlot = "MORNING" | "AFTERNOON" | "FULL_DAY";

export interface JobAuditor {
  id:          number;
  firstName:   string;
  lastName:    string;
  email:       string;
  created_at?: string;
  updated_at?: string;
}

export interface JobStageDetail {
  stageName: string;
  md:        string;
  docReview: string;
  date:      string;
  auditBy:   JobAuditor;
}

export interface JobTemplate {
  id:        number;
  name:      string;
  version:   string;
  contents:  JobTemplateContent[];
  filePath:  string;
  isActive:  boolean;
  stageName: string;
  url:       string;
}

export interface JobTemplateContent {
  id:              number;
  title:           string | null;
  content:         string;
  endTime:         string;
  startTime:       string;
  created_at:      string;
  created_by:      number;
  updated_at:      string;
  template_id:     number;
  functional_area: string | null;
}

export interface JobCompany {
  id:   number;
  name: string;
}

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

// ✅ NEW — Audit Stage entity from /company-audit-stages
export interface AuditStage {
  id:   number;
  name: string;
}

export interface JobCompanySnapshot {
  companyFax:                string;
  companyName:               string;
  companycity:               string;
  companyScope:              string;
  companyemail:              string;
  companymobile:             string;
  companyAddress:            string;
  companyRefrence:           string;
  companyvalidity:           string;
  companytelephone:          string;
  companydesignation:        string;
  companyaccreditation:      string;
  companycontact_person:     string;
  companycertification_body: string;
}

export interface Job {
  id:                         number;
  company:                    JobCompany;
  jobCodes:                   string[];
  stage:                      JobStage;
  stages:                     JobStageDetail[];
  template:                   JobTemplate;
  companySnapshot:            JobCompanySnapshot;
  standards:                  JobStandard[];
  leadAuditor:                JobAuditor;
  auditStageId?:              number;           // ✅ added
  date:                       string;
  docReview:                  string;
  numEmployees:               number;
  naceEacCodes:               string;
  md:                         string;
  mdRisk:                     MdRisk;
  scheduleSlot:               ScheduleSlot;
  expectedSurveillanceDate:   string;
  expectedIADate:             string;
  expectedMRMDate:            string;
  expectedInitialInquiryDate: string;
  expectedInitial_Stage1_Date:string;
  prepareDate:                string;
  approvedDate:               string;
  createdAt:                  string;
  updatedAt:                  string;
}

// ─── DTOs ─────────────────────────────────────────────────────────────────────
export interface CreateJobDto {
  company_id:     number;
  template_id:    number;
  auditStageId?:  number;           // ✅ added
  stage:          JobStage;
  standard_ids:   number[];
  leadAuditorId:  number;
  date:           string;
  docReview:      string;
  numEmployees:   number;
  naceEacCodes:   string;
  md:             string;
  mdRisk:         MdRisk;
  scheduleSlot:   ScheduleSlot;
  prepareDate?:   string;
  approvedDate?:  string;
}

export type UpdateJobDto = Partial<CreateJobDto>;

// ─── Paginated response ───────────────────────────────────────────────────────
export interface PaginatedJobsResponse {
  data: Job[];
  meta: {
    total:       number;
    page:        number;
    limit:       number;
    totalPages:  number;
    hasNextPage: boolean;
    hasPrevPage: boolean;
  };
}

// ─── Table row ────────────────────────────────────────────────────────────────
export interface JobRow {
  sno:          number;
  id:           number;
  companyName:  string;
  companyId:    number;
  jobCodes:     string[];
  jobCodesStr:  string;
  stage:        JobStage;
  templateName: string;
  leadAuditor:  string;
  date:         string;
  mdRisk:       MdRisk;
  scheduleSlot: ScheduleSlot;
  standards:    JobStandard[];
  numEmployees: number;
  md:           string;
  naceEacCodes: string;
  pdfUrl:       string;
  createdAt:    string;
  updatedAt:    string;
  raw:          Job;
  [key: string]: any;
}

// ─── Dropdown option (shared) ─────────────────────────────────────────────────
export interface SelectOption {
  value: number | string;
  label: string;
}
