import { Employee } from './Employee';

export type GrievanceStatus =
  | 'draft'
  | 'submitted'
  | 'acknowledged'
  | 'under_investigation'
  | 'pending_hearing'
  | 'decision_issued'
  | 'appealed'
  | 'appeal_hearing'
  | 'appeal_decided'
  | 'escalated_to_nlc'
  | 'closed'
  | 'reopened';

export type GrievanceCategory =
  | 'harassment'
  | 'sexual_harassment'
  | 'discrimination'
  | 'unfair_treatment'
  | 'pay_dispute'
  | 'unsafe_conditions'
  | 'policy_violation'
  | 'bullying'
  | 'workload'
  | 'other';

export type GrievanceSeverity = 'low' | 'medium' | 'high' | 'critical';

export type GrievanceAgainstType = 'employee' | 'manager' | 'department' | 'policy' | 'organization';

export type GrievanceDecisionOutcome =
  | 'upheld'
  | 'partially_upheld'
  | 'not_upheld'
  | 'settled'
  | 'withdrawn';

export type GrievanceAppealOutcome = 'upheld' | 'partially_upheld' | 'not_upheld';

export type GrievanceDocumentType =
  | 'supporting_evidence'
  | 'investigation_report'
  | 'hearing_notes'
  | 'decision_letter'
  | 'appeal_letter'
  | 'other';

export type GrievanceHearingType = 'initial' | 'appeal';

export interface Grievance {
  id: string;
  case_number: string;
  employee_id: string;
  grievance_category: GrievanceCategory;
  severity: GrievanceSeverity;
  subject: string;
  description: string;
  incident_date?: string | null;
  incident_location?: string | null;
  grievance_against_type: GrievanceAgainstType;
  grievance_against_employee_id?: string | null;
  is_anonymous: boolean;
  status: GrievanceStatus;
  assigned_hr_id?: string | null;
  investigator_id?: string | null;
  target_resolution_date?: string | null;
  actual_resolution_date?: string | null;
  sla_breached: boolean;
  decision_outcome?: GrievanceDecisionOutcome | null;
  decision_notes?: string | null;
  decision_date?: string | null;
  appeal_requested: boolean;
  appeal_date?: string | null;
  appeal_outcome?: GrievanceAppealOutcome | null;
  appeal_notes?: string | null;
  escalated_to_nlc: boolean;
  nlc_reference_number?: string | null;
  nlc_escalation_date?: string | null;
  closure_notes?: string | null;
  corrective_actions?: string | null;
  follow_up_date?: string | null;
  submitted_by?: string | null;
  created_at: string;
  updated_at: string;

  employee?: Employee;
  grievance_against_employee?: Employee;
  assigned_hr?: Employee;
  investigator?: Employee;
  documents?: GrievanceDocument[];
  timeline?: GrievanceTimeline[];
  hearings?: GrievanceHearing[];
}

export interface GrievanceDocument {
  id: string;
  grievance_id: string;
  document_type: GrievanceDocumentType;
  file_path: string;
  file_name: string;
  uploaded_by?: string | null;
  created_at: string;
  updated_at: string;
}

export interface GrievanceTimeline {
  id: string;
  grievance_id: string;
  action: string;
  old_status?: string | null;
  new_status?: string | null;
  notes?: string | null;
  performed_by?: string | null;
  created_at: string;
  updated_at: string;
}

export interface GrievanceHearing {
  id: string;
  grievance_id: string;
  hearing_type: GrievanceHearingType;
  hearing_date: string;
  hearing_location?: string | null;
  companion_present: boolean;
  companion_name?: string | null;
  notes?: string | null;
  outcome?: string | null;
  conducted_by?: string | null;
  created_at: string;
  updated_at: string;
  conductor?: Employee;
}

export interface CreateGrievancePayload {
  employee_id?: string;
  grievance_category: GrievanceCategory;
  severity: GrievanceSeverity;
  subject: string;
  description: string;
  incident_date?: string;
  incident_location?: string;
  grievance_against_type: GrievanceAgainstType;
  grievance_against_employee_id?: string;
  is_anonymous?: boolean;
  status?: 'draft' | 'submitted';
}

export interface UpdateGrievancePayload {
  id: string;
  grievance_category?: GrievanceCategory;
  severity?: GrievanceSeverity;
  subject?: string;
  description?: string;
  incident_date?: string | null;
  incident_location?: string | null;
  grievance_against_type?: GrievanceAgainstType;
  grievance_against_employee_id?: string | null;
  is_anonymous?: boolean;
  assigned_hr_id?: string | null;
  investigator_id?: string | null;
  decision_outcome?: GrievanceDecisionOutcome | null;
  decision_notes?: string | null;
  decision_date?: string | null;
  appeal_requested?: boolean;
  appeal_date?: string | null;
  appeal_outcome?: GrievanceAppealOutcome | null;
  appeal_notes?: string | null;
  escalated_to_nlc?: boolean;
  nlc_reference_number?: string | null;
  nlc_escalation_date?: string | null;
  closure_notes?: string | null;
  corrective_actions?: string | null;
  follow_up_date?: string | null;
  actual_resolution_date?: string | null;
  target_resolution_date?: string | null;
}

export interface UpdateGrievanceStatusPayload {
  id: string;
  status: GrievanceStatus;
  notes?: string;
  decision_outcome?: GrievanceDecisionOutcome;
  decision_notes?: string;
  decision_date?: string;
  appeal_outcome?: GrievanceAppealOutcome;
  appeal_notes?: string;
  appeal_date?: string;
  nlc_reference_number?: string;
  nlc_escalation_date?: string;
  closure_notes?: string;
  corrective_actions?: string;
  follow_up_date?: string;
  actual_resolution_date?: string;
  assigned_hr_id?: string;
  investigator_id?: string;
}

export interface CreateGrievanceHearingPayload {
  grievance_id: string;
  hearing_type: GrievanceHearingType;
  hearing_date: string;
  hearing_location?: string;
  companion_present?: boolean;
  companion_name?: string;
  notes?: string;
  outcome?: string;
  conducted_by?: string;
}

export interface UpdateGrievanceHearingPayload extends CreateGrievanceHearingPayload {
  hearing_id: string;
}

export interface UploadGrievanceDocumentPayload {
  grievance_id: string;
  document_type: GrievanceDocumentType;
  file: File;
}

export interface DeleteGrievanceDocumentPayload {
  grievance_id: string;
  document_id: string;
}

export interface GrievanceStats {
  total: number;
  by_status: Record<string, number>;
  sla_breached: number;
  resolved: number;
  resolved_within_sla: number;
  average_resolution_days: number;
}
