import { ApiPropertyOptional } from '@nestjs/swagger';
import { ListingStatus, PropertyType, TransactionType } from '@prisma/client';
import { Transform, Type } from 'class-transformer';
import { IsEnum, IsNumber, IsOptional, IsString, Max, Min } from 'class-validator';

export class SearchListingsDto {
  @ApiPropertyOptional({ enum: ListingStatus, example: 'ACTIVE', description: 'Filter by listing status' })
  @IsOptional()
  @IsEnum(ListingStatus)
  status?: ListingStatus;

  @ApiPropertyOptional({ enum: TransactionType, example: 'SALE', description: 'Filter by transaction type' })
  @IsOptional()
  @IsEnum(TransactionType)
  transactionType?: TransactionType;

  @ApiPropertyOptional({ enum: PropertyType, example: 'APARTMENT', description: 'Filter by property type' })
  @IsOptional()
  @IsEnum(PropertyType)
  propertyType?: PropertyType;

  @ApiPropertyOptional({ example: 'Hồ Chí Minh', description: 'Filter by city / province' })
  @IsOptional()
  @IsString()
  city?: string;

  @ApiPropertyOptional({ example: 'Quận 2', description: 'Filter by district' })
  @IsOptional()
  @IsString()
  district?: string;

  @ApiPropertyOptional({ type: String, example: '2000000000', description: 'Minimum price in VND' })
  @IsOptional()
  @Transform(({ value }) => (value != null ? BigInt(value) : undefined))
  minPrice?: bigint;

  @ApiPropertyOptional({ type: String, example: '10000000000', description: 'Maximum price in VND' })
  @IsOptional()
  @Transform(({ value }) => (value != null ? BigInt(value) : undefined))
  maxPrice?: bigint;

  @ApiPropertyOptional({ example: 50, description: 'Minimum area in square metres' })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  minArea?: number;

  @ApiPropertyOptional({ example: 200, description: 'Maximum area in square metres' })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  maxArea?: number;

  @ApiPropertyOptional({ example: 2, description: 'Filter by number of bedrooms' })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  bedrooms?: number;

  @ApiPropertyOptional({ example: 1, description: 'Page number (starts at 1)' })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  @Min(1)
  page?: number;

  @ApiPropertyOptional({ example: 20, description: 'Items per page (max 100)' })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  @Min(1)
  @Max(100)
  limit?: number;
}
