import type { Shift } from "./shift.models";
import { default_expense, type Expense } from "src/modules/timesheets/models/expense.models";

export type Week<T> = {
    sun: T;
    mon: T;
    tue: T;
    wed: T;
    thu: T;
    fri: T;
    sat: T;
};

export interface PayPeriodDetails {
    weeks: PayPeriodDetailsWeek[];
    employee_full_name: string;
}

export interface PayPeriodDetailsWeek {
    is_approved: boolean;
    shifts:   Week<PayPeriodDetailsWeekDayShifts>
    expenses: Week<PayPeriodDetailsWeekDayExpenses>;
}

export interface PayPeriodDetailsWeekDayShifts {
    shifts:          Shift[];
    regular_hours:   number;
    evening_hours:   number;
    emergency_hours: number;
    overtime_hours:  number;
    total_hours:     number;
    short_date:      string;
    break_duration?: number;
}

export interface PayPeriodDetailsWeekDayExpenses {
    expenses: Expense[];
    total_expenses: number;
    total_mileage: number;
}

const makeWeek = <T>(factory: ()=> T): Week<T> => ({
    sun: factory(),
    mon: factory(),
    tue: factory(),
    wed: factory(),
    thu: factory(),
    fri: factory(),
    sat: factory(),
});

const emptyDailySchedule = (): PayPeriodDetailsWeekDayShifts => ({
    shifts: [],
    regular_hours: 0,
    evening_hours: 0,
    emergency_hours: 0,
    overtime_hours: 0,
    total_hours: 0,
    short_date: "",
    break_duration: 0,
});

const emptyDailyExpenses = (): PayPeriodDetailsWeekDayExpenses => ({
    expenses: [default_expense,],
    total_expenses: -1,
    total_mileage: -1,
});

export const defaultPayPeriodDetailsWeek = (): PayPeriodDetailsWeek => ({
    is_approved: false,
    shifts: makeWeek(emptyDailySchedule),
    expenses: makeWeek(emptyDailyExpenses),
});

export const default_pay_period_details: PayPeriodDetails = {
    weeks: [ defaultPayPeriodDetailsWeek(), ],
    employee_full_name: "",
}