// ============================================================================
// Shared Types
// ============================================================================

export interface ShiftInfo {
  zs_id: number;
  zs_date: string;
  zs_start_time: string;
  zs_end_time: string;
  zs_status?: string;
  display_name: string;
  department?: {
    ber_id: number;
    ber_name: string;
  } | null;
  template?: {
    zst_name: string;
    zst_color: string;
  } | null;
}

export interface UserInfo {
  usr_id: number;
  name: string;
}

export interface RoleInfo {
  zr_id: number;
  zr_name: string;
  zr_color?: string | null;
}

// ============================================================================
// My Assignments (current month shifts)
// ============================================================================

export interface MyAssignment {
  zsa_id: number;
  shift: ShiftInfo | null;
  role: RoleInfo | null;
  zsa_replacement_status: string | null;
  zsa_replacement_requested_at: string | null;
  zsa_replacement_notes: string | null;
  can_request_replacement: boolean;
  can_request_swap: boolean;
}

export interface MyAssignmentsResponse {
  assignments: MyAssignment[];
  count: number;
}

// ============================================================================
// Swap Types
// ============================================================================

export interface SwapCandidate {
  zsa_id: number;
  user: UserInfo;
  shift: ShiftInfo;
  role: RoleInfo | null;
  is_compatible: boolean;
  incompatibility_reason: string | null;
  conflicts: string[];
}

export interface SwapCandidatesResponse {
  candidates: SwapCandidate[];
  count: number;
}

export interface IncomingSwapRequest {
  type: 'incoming';
  request_assignment_id: number;
  my_assignment_id: number;
  other_user: UserInfo;
  their_shift: ShiftInfo;
  my_shift: ShiftInfo;
  requested_at: string | null;
}

export interface OutgoingSwapRequest {
  type: 'outgoing';
  request_assignment_id: number;
  target_assignment_id: number;
  other_user: UserInfo;
  my_shift: ShiftInfo;
  their_shift: ShiftInfo;
  requested_at: string | null;
}

export type SwapRequest = IncomingSwapRequest | OutgoingSwapRequest;

export interface PendingSwapResponse {
  incoming_requests: IncomingSwapRequest[];
  outgoing_requests: OutgoingSwapRequest[];
  incoming_count: number;
  outgoing_count: number;
  total_count: number;
}

// ============================================================================
// Replacement Types
// ============================================================================

export interface OutgoingReplacementRequest {
  type: 'outgoing';
  request_assignment_id: number;
  my_shift: ShiftInfo;
  required_role: RoleInfo | null;
  zsa_replacement_notes: string | null;
  requested_at: string | null;
}

export interface IncomingReplacementOpportunity {
  type: 'incoming';
  request_assignment_id: number;
  original_user: UserInfo | null;
  is_unassigned: boolean;
  their_shift: ShiftInfo;
  required_role: RoleInfo | null;
  zsa_replacement_notes: string | null;
  requested_at: string | null;
  user_is_compatible: boolean;
  incompatibility_reason: string | null;
}

export interface PendingReplacementResponse {
  outgoing_requests: OutgoingReplacementRequest[];
  incoming_opportunities: IncomingReplacementOpportunity[];
  outgoing_count: number;
  incoming_count: number;
  total_count: number;
}
