import { Type } from "class-transformer";
import { IsDateString, IsEnum, IsInt, IsOptional, Min } from "class-validator";
import { TransactionStatus } from "generated/prisma/client";

export enum ExportFormat {
    XLSX = 'xlsx',
    CSV = 'csv',
}

export interface ExportColumn {
    header: string;
    key: string;
    width?: number;
    isPercent?: boolean;
}

export interface ExportOptions {
    filename: string;
    sheetName?: string;
    columns: ExportColumn[];
    data: Record<string, any>[];
    format: ExportFormat;
}

// Generic query DTO — reused across all modules
export class ExportQueryDto {
    @IsOptional()
    @IsDateString()
    startDate?: string;

    @IsOptional()
    @IsDateString()
    endDate?: string;

    @IsOptional()
    branchId?: string;

    @IsOptional()
    @IsEnum(TransactionStatus)
    status?: TransactionStatus;

    @IsEnum(ExportFormat)
    @IsOptional()
    format: ExportFormat = ExportFormat.XLSX;

    @IsOptional()
    @Type(() => Number)
    @IsInt()
    @Min(1)
    limit?: number;

    @IsOptional()
    @Type(() => Number)
    @IsInt()
    @Min(0)
    offset?: number;
}