export type EmployeeRequestStatus = 'draft' | 'pending' | 'approved' | 'rejected' | 'cancelled';

export interface EmployeeRequest {
  id: string;
  employee_id: string;
  request_type_id: string;
  reason?: string | null;
  status: EmployeeRequestStatus;
  submitted_at?: string | null;
  employee?: {
    employee_id: string;
    staff_id?: string;
    firstname?: string;
    lastname?: string;
    branch_name?: string | null;
    position_name?: string | null;
  };
  request_type?: RequestType;
  approvals?: EmployeeRequestApproval[];
  excuse_duty_detail?: ExcuseDutyDetail | null;
  overtime_detail?: OvertimeRequestDetail | null;
  medical_support_detail?: MedicalSupportDetail | null;
  created_at?: string;
  updated_at?: string;
  deleted_at?: string | null;
}

export interface RequestType {
  id: string;
  name: string;
  slug: string;
  description?: string | null;
  is_active: boolean;
  is_system?: boolean;
}

export interface ExcuseDutyDetail {
  id: string;
  employee_request_id: string;
  date: string;
  end_date?: string | null;
  duration_hours?: number | null;
  reason_category?: 'court_appearance' | 'funeral' | 'official_event' | 'religious' | 'other' | null;
}

export interface OvertimeRequestDetail {
  id: string;
  employee_request_id: string;
  date: string;
  start_time: string;
  end_time: string;
  expected_hours?: number | null;
  overtime_type?: 'regular' | 'weekend' | 'holiday' | null;
}

export interface MedicalSupportDetail {
  id: string;
  employee_request_id: string;
  support_type: string;
  medical_facility?: string | null;
  estimated_cost?: number | null;
  currency?: string | null;
  beneficiary_type?: 'self' | 'spouse' | 'child' | 'dependant' | null;
}

export interface EmployeeRequestApproval {
  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 EmployeeRequestFilters {
  status?: EmployeeRequestStatus;
  employee_id?: string;
  request_type_id?: string;
  search?: string;
  per_page?: number;
}

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

export interface CreateEmployeeRequestPayload {
  employee_id: string;
  request_type_id: string;
  reason?: string;
  excuse_duty?: {
    date: string;
    end_date?: string;
    duration_hours?: number;
    reason_category?: string;
  };
  overtime?: {
    date: string;
    start_time: string;
    end_time: string;
    expected_hours?: number;
    overtime_type?: string;
  };
  medical_support?: {
    support_type: string;
    medical_facility?: string;
    estimated_cost?: number;
    currency?: string;
    beneficiary_type?: string;
  };
}

export interface EmployeeRequestActionResponse {
  message?: string;
  data?: EmployeeRequest;
  id?: string;
  status?: string;
  employee_id?: string;
  request_type_id?: string;
  reason?: string | null;
  submitted_at?: string | null;
  employee?: EmployeeRequest['employee'];
  request_type?: RequestType;
  approvals?: EmployeeRequestApproval[];
  excuse_duty_detail?: ExcuseDutyDetail | null;
  overtime_detail?: OvertimeRequestDetail | null;
  medical_support_detail?: MedicalSupportDetail | null;
  created_at?: string;
  updated_at?: string;
}

export interface PendingRequestApproval {
  id: string;
  employee_request_id: string;
  approver_id: string;
  step_number: number;
  status: string;
  comments?: string | null;
  acted_at?: string | null;
  created_at?: string;
  employee_request?: EmployeeRequest;
}

export interface RequestWorkflow {
  id: string;
  name: string;
  description?: string | null;
  is_default: boolean;
  is_active: boolean;
  steps?: RequestWorkflowStep[];
  assignments?: RequestWorkflowAssignment[];
  created_at?: string;
  updated_at?: string;
}

export interface RequestWorkflowStep {
  id: string;
  workflow_id: string;
  step_number: number;
  approver_type: 'direct_supervisor' | 'position' | 'specific_user' | 'role';
  approver_position_id?: string | null;
  approver_user_id?: string | null;
  approver_role?: string | null;
  can_skip: boolean;
  auto_approve_after_days?: number | null;
}

export interface RequestWorkflowAssignment {
  id: string;
  workflow_id: string;
  employee_id?: string | null;
  employee_category_id?: string | null;
  position_id?: string | null;
}
