import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { IsBoolean, IsIn, IsInt, IsOptional, IsString, Max, MaxLength, Min, MinLength } from 'class-validator';

export class CreateRegionDto {
    @ApiProperty({ example: 'Mumbai, Maharashtra' })
    @IsString()
    @MinLength(2)
    @MaxLength(100)
    @Transform(({ value }) => (typeof value === 'string' ? value.trim() : value))
    name: string;
}

export class UpdateRegionDto {
    @ApiProperty({ required: false, example: 'Mumbai, Maharashtra' })
    @IsOptional()
    @IsString()
    @MinLength(2)
    @MaxLength(100)
    @Transform(({ value }) => (typeof value === 'string' ? value.trim() : value))
    name?: string;

    @ApiProperty({ required: false, description: 'false hides the region from new agents; existing agents keep it' })
    @IsOptional()
    @IsBoolean()
    is_active?: boolean;
}

export class RegionListDto {
    @ApiProperty({ required: false, default: 1 })
    @IsOptional()
    @Transform(({ value }) => Number(value))
    @IsInt()
    @Min(1)
    page: number = 1;

    @ApiProperty({ required: false, default: 10 })
    @IsOptional()
    @Transform(({ value }) => Number(value))
    @IsInt()
    @Min(1)
    @Max(100)
    limit: number = 10;

    @ApiProperty({ required: false })
    @IsOptional()
    @IsString()
    search?: string;

    @ApiProperty({ required: false, enum: ['true', 'false'], description: 'Filter by status' })
    @IsOptional()
    @IsIn(['true', 'false'])
    is_active?: string;
}
