import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ProjectDevelopmentStatus } from '@prisma/client';
import { Type } from 'class-transformer';
import {
  IsString,
  IsNumber,
  IsEnum,
  IsOptional,
  IsArray,
  IsObject,
  Min,
  Max,
  MaxLength,
  IsDateString,
} from 'class-validator';

export class CreateProjectDto {
  @ApiProperty({ example: 'Vinhomes Grand Park', description: 'Tên dự án' })
  @IsString()
  @MaxLength(200)
  name!: string;

  @ApiProperty({ example: 'vinhomes-grand-park', description: 'URL slug (unique)' })
  @IsString()
  @MaxLength(100)
  slug!: string;

  @ApiProperty({ example: 'Vingroup' })
  @IsString()
  developer!: string;

  @ApiPropertyOptional({ example: 'https://example.com/logo.png' })
  @IsOptional()
  @IsString()
  developerLogo?: string;

  @ApiProperty({ example: 10000, description: 'Tổng số căn hộ/đơn vị' })
  @IsNumber()
  @Type(() => Number)
  @Min(1)
  totalUnits!: number;

  @ApiProperty({ enum: ProjectDevelopmentStatus, example: 'UNDER_CONSTRUCTION' })
  @IsEnum(ProjectDevelopmentStatus)
  status!: ProjectDevelopmentStatus;

  @ApiProperty({ example: 10.8231, description: 'Latitude' })
  @IsNumber()
  @Type(() => Number)
  @Min(-90)
  @Max(90)
  latitude!: number;

  @ApiProperty({ example: 106.8368, description: 'Longitude' })
  @IsNumber()
  @Type(() => Number)
  @Min(-180)
  @Max(180)
  longitude!: number;

  @ApiProperty({ example: 'Phường Long Thạnh Mỹ, TP. Thủ Đức' })
  @IsString()
  address!: string;

  @ApiProperty({ example: 'Long Thạnh Mỹ' })
  @IsString()
  ward!: string;

  @ApiProperty({ example: 'Thủ Đức' })
  @IsString()
  district!: string;

  @ApiProperty({ example: 'Hồ Chí Minh' })
  @IsString()
  city!: string;

  @ApiPropertyOptional({ description: 'Mô tả dự án' })
  @IsOptional()
  @IsString()
  description?: string;

  @ApiPropertyOptional({ description: 'Tiện ích dự án (JSON)' })
  @IsOptional()
  @IsObject()
  amenities?: Record<string, unknown>;

  @ApiPropertyOptional({ example: 'https://example.com/masterplan.jpg' })
  @IsOptional()
  @IsString()
  masterPlanUrl?: string;

  @ApiPropertyOptional({ example: '3000000000', description: 'Giá thấp nhất (VND)' })
  @IsOptional()
  @IsString()
  minPrice?: string;

  @ApiPropertyOptional({ example: '15000000000', description: 'Giá cao nhất (VND)' })
  @IsOptional()
  @IsString()
  maxPrice?: string;

  @ApiPropertyOptional({ description: 'Giá/m² range (JSON)' })
  @IsOptional()
  @IsObject()
  pricePerM2Range?: Record<string, unknown>;

  @ApiPropertyOptional({ example: 271, description: 'Tổng diện tích (ha)' })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  @Min(0)
  totalArea?: number;

  @ApiPropertyOptional({ example: 14 })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  buildingCount?: number;

  @ApiPropertyOptional({ example: 35 })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  floorCount?: number;

  @ApiPropertyOptional({ description: 'Loại căn hộ (JSON)' })
  @IsOptional()
  @IsObject()
  unitTypes?: Record<string, unknown>;

  @ApiPropertyOptional({ example: ['cao-cap', 'can-ho'], description: 'Tags' })
  @IsOptional()
  @IsArray()
  @IsString({ each: true })
  tags?: string[];

  @ApiPropertyOptional({
    example: ['Gia đình trẻ', 'Chuyên gia nước ngoài'],
    description: 'Các nhóm khách phù hợp với dự án',
  })
  @IsOptional()
  @IsArray()
  @IsString({ each: true })
  suitableFor?: string[];

  @ApiPropertyOptional({
    description: 'Mô tả ngắn vì sao khu vực này phù hợp',
    maxLength: 2000,
  })
  @IsOptional()
  @IsString()
  @MaxLength(2000)
  whyThisLocation?: string;

  @ApiPropertyOptional({ example: '2020-06-01', description: 'Ngày khởi công' })
  @IsOptional()
  @IsDateString()
  startDate?: string;

  @ApiPropertyOptional({ example: '2025-12-31', description: 'Ngày dự kiến hoàn thành' })
  @IsOptional()
  @IsDateString()
  completionDate?: string;
}
