import { ShiftAssignedDay } from '../../business/models/shiftManagement/shiftAssignedDay';
import { ShiftAssignedShiftType } from '../../business/types/shiftManagement/assignedShiftType';
import { ShiftAssignedDayResponse } from '../dtos/shiftAssignedDayResponse';

export const mapShiftAssignedDayToResponse = (shiftAssignedDay: ShiftAssignedDay, employeeId: string): ShiftAssignedDayResponse => {
    const timeSlots: [string, string][] =
        shiftAssignedDay.shiftAssociations?.flatMap(
            (shift) => shift.timeSlots?.map((slot) => [slot.startTime, slot.endTime] as [string, string]) ?? [],
        ) ?? [];

    return {
        createdAt: shiftAssignedDay.createdAt,
        date: shiftAssignedDay.dateString,
        employeeId,
        id: shiftAssignedDay.id,
        isWorkday: shiftAssignedDay.shiftAssociations?.some((shift) => shift.type === ShiftAssignedShiftType.WORK) ?? false,
        timeSlots,
        updatedAt: shiftAssignedDay.updatedAt,
        userId: shiftAssignedDay.userId,
    };
};
