import {
    IsOptional,
    IsString,
    IsNumber,
    Min,
    IsIn,
    IsEnum,
    IsBoolean,
} from 'class-validator';
import { Type, Transform } from 'class-transformer';
import { ApiPropertyOptional } from '@nestjs/swagger';
import { PlanEnum } from '../interface/plan.interface';

const sortOrderOptions = ['asc', 'desc'] as const;
type SortOrder = (typeof sortOrderOptions)[number];

export class FindRestaurantsDto {
    @ApiPropertyOptional({ default: 1, minimum: 1 })
    @IsOptional()
    @Type(() => Number)
    @IsNumber()
    @Min(1)
    page: number = 1;

    @ApiPropertyOptional({ default: 10, minimum: 1 })
    @IsOptional()
    @Type(() => Number)
    @IsNumber()
    @Min(1)
    limit: number = 10;

    @ApiPropertyOptional({
        description: 'Search by name, slug, domain, or address',
    })
    @IsOptional()
    @IsString()
    search?: string;

    @ApiPropertyOptional({
        description: 'Filter by active status',
        type: Boolean,
    })
    @IsOptional()
    @Transform(({ value }) => {
        if (value === 'true') return true;
        if (value === 'false') return false;
        return value;
    })
    @IsBoolean()
    isActive?: boolean;

    @ApiPropertyOptional({
        enum: PlanEnum,
        description: 'Filter by plan type',
    })
    @IsOptional()
    @IsEnum(PlanEnum)
    plan?: PlanEnum;

    @ApiPropertyOptional({ default: 'createdAt' })
    @IsOptional()
    @IsString()
    orderBy: string = 'createdAt';

    @ApiPropertyOptional({
        enum: sortOrderOptions,
        default: 'desc',
    })
    @IsOptional()
    @IsIn(sortOrderOptions)
    order: SortOrder = 'desc';
}

