import { Transform } from "class-transformer";
import { IsBoolean, IsInt, IsOptional, Max, Min } from "class-validator";
import { ShiftType } from "src/time-and-attendance/shifts/shift.dto";

const toBoolean = (v: any) => {
    if (typeof v === 'boolean') return v;
    if (typeof v === 'string') return ['true', '1', 'on', 'yes'].includes(v.toLowerCase());
    return false;
}

export class ExportCsvOptionsDto {

    @Transform(({ value }) => parseInt(value, 10))
    @IsInt() @Min(2023)
    year!: number;

    @Transform(({ value }) => parseInt(value, 10))
    @IsInt() @Min(1) @Max(26)
    period_no!: number;

    @IsOptional() @IsBoolean()
    @Transform(({ value }) => toBoolean(value))
    approved?: boolean = true;

    @IsOptional() @IsBoolean()
    @Transform(({ value }) => toBoolean(value))
    shifts?: boolean = true;

    @IsOptional() @IsBoolean()
    @Transform(({ value }) => toBoolean(value))
    expenses?: boolean = true;

    @IsOptional() @IsBoolean()
    @Transform(({ value }) => toBoolean(value))
    holiday?: boolean = true;

    @IsOptional() @IsBoolean()
    @Transform(({ value }) => toBoolean(value))
    vacation?: boolean = true;

    @IsOptional() @IsBoolean()
    @Transform(({ value }) => toBoolean(value))
    targo?: boolean = true;

    @IsOptional() @IsBoolean()
    @Transform(({ value }) => toBoolean(value))
    solucom?: boolean = true;
}

export interface CsvRow {
    compagnie_no: number;
    employee_matricule: number;
    releve: number;
    type_transaction: string;
    code: number;
    quantite_hre: number | undefined;
    taux_horaire: string | undefined;
    montant: number | undefined;
    semaine_no: number;
    division_no: number | undefined;
    service_no: number | undefined;
    departem_no: number | undefined;
    sous_departem_no: number | undefined;
    date_transaction: string;
    premier_jour_absence: string | undefined;
    dernier_jour_absence: string | undefined;
}

export type InternalCsvRow = CsvRow & { timesheet_id: number; shift_date: Date; }


export type CsvFilters = {
    companyName: 'Targo' | 'Solucom';
    includeExpenses: boolean;
    shiftTypes: ShiftType[];
};