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

export class GetValuationDto {
  @ApiPropertyOptional({ description: 'Property ID for valuation' })
  @IsOptional()
  @IsString()
  propertyId?: string;

  @ApiPropertyOptional({ description: 'Latitude (required if no propertyId)' })
  @ValidateIf((o) => !o.propertyId)
  @IsNumber()
  @Transform(({ value }) => (value != null ? parseFloat(value) : undefined))
  latitude?: number;

  @ApiPropertyOptional({ description: 'Longitude (required if no propertyId)' })
  @ValidateIf((o) => !o.propertyId)
  @IsNumber()
  @Transform(({ value }) => (value != null ? parseFloat(value) : undefined))
  longitude?: number;

  @ApiPropertyOptional({ description: 'Area in square meters (required if no propertyId)' })
  @ValidateIf((o) => !o.propertyId)
  @IsNumber()
  @Transform(({ value }) => (value != null ? parseFloat(value) : undefined))
  areaM2?: number;

  @ApiPropertyOptional({ enum: PropertyType, description: 'Property type filter' })
  @IsOptional()
  @IsEnum(PropertyType)
  propertyType?: PropertyType;
}
