import type { ShiftType } from "src/modules/timesheets/models/shift.models";

export type Weekday = 'SUN' | 'MON' | 'TUE' | 'WED' | 'THU' | 'FRI' | 'SAT';

export const WEEKDAYS: Weekday[] = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'];

export type PresetManagerMode = 'create' | 'update' | 'copy' | 'delete';

export class SchedulePreset {
    id: number;
    name: string;
    shifts: SchedulePresetShift[];

    constructor(id?: number, name?: string, shifts?: SchedulePresetShift[]) {
        this.id = id ?? -1;
        this.name = name ?? 'default';
        this.shifts = shifts ?? [];
    }
}

export class SchedulePresetShift {
    preset_id: number;
    week_day: Weekday;
    type: ShiftType;
    start_time: string;
    end_time: string;
    is_remote: boolean;
    
    constructor(weekday: Weekday) {
        this.preset_id = -1;
        this.week_day = weekday;
        this.type = 'REGULAR';
        this.start_time = '00:00';
        this.end_time = '00:00';
        this.is_remote = false;
    }
}

export class SchedulePresetFrontend {
    id: number;
    name: string;
    weekdays: WeekdayPresetShifts[];

    constructor(schedule_preset?: SchedulePreset) {
        this.id = schedule_preset?.id ?? -1;
        this.name = schedule_preset?.name ?? '';
        this.weekdays = WEEKDAYS.map(day => ({
            day,
            is_error: false,
            shifts: schedule_preset !== undefined ? schedule_preset?.shifts.filter(shift => shift.week_day === day) : [],
        }))
    }
}

export interface WeekdayPresetShifts {
    day: Weekday;
    is_error: boolean;
    shifts: SchedulePresetShift[];
}