export type LeaveRequestStatus =
  | 'draft'
  | 'pending'
  | 'approved'
  | 'rejected'
  | 'cancelled'
  | 'recalled';

export interface LeaveRequest {
  id: string;
  employee_id: string;
  leave_type_id: string;
  start_date: string;
  end_date: string;
  total_days: number;
  reason?: string | null;
  contact_phone?: string | null;
  contact_email?: string | null;
  relief_officer_id?: string | null;
  handover_notes?: string | null;
  status: LeaveRequestStatus;
  applied_by?: string | null;
  applied_at?: string | null;
  current_approval_step: number;
  attachment_path?: string | null;
  attachment_url?: string | null;
  employee?: {
    employee_id: string;
    staff_id?: string;
    firstname?: string;
    lastname?: string;
    branch_name?: string | null;
    position_name?: string | null;
  };
  leave_type?: {
    id: string;
    name: string;
    code: string;
    color_code?: string | null;
  };
  relief_officer?: {
    employee_id: string;
    firstname?: string;
    lastname?: string;
  };
  applied_by_user?: {
    id: string;
    name: string;
  };
  approvals?: LeaveRequestApproval[];
  created_at?: string;
  updated_at?: string;
  deleted_at?: string | null;
}

export interface LeaveRequestApproval {
  id: string;
  step_number: number;
  status: 'pending' | 'approved' | 'rejected' | 'skipped';
  comments?: string | null;
  acted_at?: string | null;
  approver?: {
    id: string;
    name: string;
    email?: string;
  };
}

export interface LeaveRequestFilters {
  status?: LeaveRequestStatus;
  employee_id?: string;
  leave_type_id?: string;
  year?: number;
  branch_id?: string;
  date_from?: string;
  date_to?: string;
  mine?: boolean;
  search?: string;
  per_page?: number;
}

export interface LeaveRequestListResponse {
  data: LeaveRequest[];
  meta?: {
    current_page: number;
    last_page: number;
    per_page: number;
    total: number;
  };
}

export interface LeaveRequestSingleResponse {
  data: LeaveRequest;
}

export interface CreateLeaveRequestPayload {
  employee_id?: string;
  leave_type_id: string;
  start_date: string;
  end_date: string;
  reason?: string;
  contact_phone?: string;
  contact_email?: string;
  relief_officer_id?: string;
  handover_notes?: string;
  attachment?: File | null;
}

export interface UpdateLeaveRequestPayload extends Partial<CreateLeaveRequestPayload> {
  id: string;
}

export interface DeleteLeaveRequestPayload {
  message: string;
  id?: string;
}

export interface LeaveRequestActionResponse {
  message: string;
  data: LeaveRequest;
}

export interface CalculateLeaveDaysPayload {
  start_date: string;
  end_date?: string;
  number_of_days?: number;
  country_code?: string;
}

export interface CalculateLeaveDaysResult {
  data: {
    total_working_days: number;
    start_date: string;
    end_date: string;
    excluded_dates: Array<{
      date: string;
      type: 'weekend' | 'holiday';
      name: string;
    }>;
  };
}
