import { Transform } from "class-transformer";
import { IsBoolean, IsInt, IsOptional, Max, Min } from "class-validator";

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 {
    company_code: number;
    external_payroll_id: number;
    full_name: string;
    bank_code: string;
    quantity_hours?: number;
    amount?: number;
    week_number: number;
    pay_date: string;
    holiday_date?: string;
}

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


export type Filters = {
    types: {
        shifts: boolean;
        expenses: boolean;
        holiday: boolean;
        vacation: boolean;
    };
    companies: {
        targo: boolean;
        solucom: boolean;
    };
    approved: boolean;
};