import { iconsPolicyTypes } from 'src/utils/vacations';

import {
  Holiday,
  ScheduleSource,
  TimeOffRequest,
  TimeSlot,
} from './timeTracking';

export type ShiftTimeSlot = {
  id: number;
  shiftId: number;
  startTime: string;
  endTime: string;
};

export type ShiftRotation = {
  id: string; // UUID v7
  name: string;
  description: string | null;
  cycleLength: number;
  workDaysCount: number;
  restDaysCount: number;
  totalHours: number;
  createdAt: string;
  updatedAt: string;
};

export type ShiftRotationDetailShift = {
  shiftCode: string;
  name: string | null;
  color: string | null;
  description: string | null;
  timeSlots: { startTime: string; endTime: string }[];
};

export type ShiftRotationDetailDay = {
  type: 'WORK' | 'REST';
  shifts: ShiftRotationDetailShift[]; // [] when REST
};

export type ShiftRotationDetail = {
  id: string;
  name: string;
  description: string | null;
  days: ShiftRotationDetailDay[];
  createdAt: string;
  updatedAt: string;
};

export type Shift = {
  code: string;
  color: ShiftColor | null;
  description: string;
  id: number;
  instanceId: number;
  isCustom: boolean;
  isHalfDayRest: boolean;
  isRest: boolean;
  lastVersion: boolean;
  name: string;
  shiftAssignedShiftId: number;
  timeSlots: ShiftTimeSlot[];
  version: number;
};

export type ShiftScheduledHours = {
  published: number;
  draft: number;
  total: number;
};

export type TimeTrackingDaySummaryHours = {
  scheduled: number;
  worked: number;
  estimated: number;
  timeOff: number | null;
};

export type TimeTrackingDaySummaryScheduleData = {
  isWorkday: boolean;
  scheduleSource: ScheduleSource;
  shiftAssignedDayId: number;
  timeSlots: TimeSlot[] | undefined;
};

export type ShiftCalendarDay = {
  daySummaryHours: TimeTrackingDaySummaryHours;
  scheduledData: TimeTrackingDaySummaryScheduleData;
  shiftScheduledHours: ShiftScheduledHours;
  shifts: Shift[];
  timeOffs?: TimeOffRequest[];
  holidays?: Holiday[];
};

export type ShiftCalendarUser = {
  userId: number;
  employeeInternalId: string;
  fullName: string;
  profilePicture: string | null;
  days: Record<string, ShiftCalendarDay>; //Key is the day in format 'YYYY-MM-DD'''
  shiftScheduleHours: ShiftScheduledHours;
};

export type ShiftFilterUser = {
  id: number;
  firstName: string;
  lastName: string;
  email: string | null;
  employeeInternalId: string;
  profilePicture: string | null;
  hiringDate: string | null;
  createdAt: string;
  deleted: boolean;
  isAgent: boolean;
};

export type SelectedAssignedShift = {
  dayId: number;
  shiftId: number;
  userId: number;
  date: string;
};

export type AssignmentType = 'day_off' | 'shift';

export type ShiftAssignCellVC = {
  userId: number;
  date: string;
};

export type CopiedShiftCell = ShiftAssignCellVC & {
  shiftIds: number[];
};

export type ShiftAssignDrawerFilters = {
  startDate: string;
  endDate: string;
  search: string;
  userIds: string;
  siteId: number | null;
  segmentationItemIds: string;
};

export enum ShiftColor {
  BLUE = '#CAD5FE',
  YELLOW = '#FFEBB8',
  GREEN = '#C3EECA',
  LILAC = '#DAD1FF',
  RED = '#FFD1D1',
  LIGHT_BLUE = '#EFFCFF',
}

export type TimeOffShiftPopoverInfo = {
  name: string;
  description: string;
  isWorkable: boolean;
  icon: keyof typeof iconsPolicyTypes;
};
