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

export class UpdateProjectDto {
  @ApiPropertyOptional() @IsOptional() @IsString() name?: string;
  @ApiPropertyOptional() @IsOptional() @IsString() developer?: string;
  @ApiPropertyOptional() @IsOptional() @IsString() developerLogo?: string | null;

  @ApiPropertyOptional() @IsOptional() @IsNumber() @Type(() => Number) @Min(1)
  totalUnits?: number;

  @ApiPropertyOptional() @IsOptional() @IsNumber() @Type(() => Number) @Min(0)
  completedUnits?: number;

  @ApiPropertyOptional({ enum: ProjectDevelopmentStatus })
  @IsOptional() @IsEnum(ProjectDevelopmentStatus)
  status?: ProjectDevelopmentStatus;

  @ApiPropertyOptional() @IsOptional() @IsString() description?: string | null;
  @ApiPropertyOptional() @IsOptional() @IsObject() amenities?: Record<string, unknown> | null;
  @ApiPropertyOptional() @IsOptional() @IsString() masterPlanUrl?: string | null;
  @ApiPropertyOptional() @IsOptional() @IsString() minPrice?: string | null;
  @ApiPropertyOptional() @IsOptional() @IsString() maxPrice?: string | null;
  @ApiPropertyOptional() @IsOptional() @IsObject() pricePerM2Range?: Record<string, unknown> | null;

  @ApiPropertyOptional() @IsOptional() @IsNumber() @Type(() => Number) @Min(0)
  totalArea?: number | null;

  @ApiPropertyOptional() @IsOptional() @IsNumber() @Type(() => Number) buildingCount?: number | null;
  @ApiPropertyOptional() @IsOptional() @IsNumber() @Type(() => Number) floorCount?: number | null;
  @ApiPropertyOptional() @IsOptional() @IsObject() unitTypes?: Record<string, unknown> | null;
  @ApiPropertyOptional() @IsOptional() @IsArray() media?: Record<string, unknown>[] | null;
  @ApiPropertyOptional() @IsOptional() @IsArray() documents?: Record<string, unknown>[] | null;
  @ApiPropertyOptional() @IsOptional() @IsArray() @IsString({ each: true }) tags?: string[];

  @ApiPropertyOptional({ 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 | null;

  @ApiPropertyOptional() @IsOptional() @IsBoolean() isVerified?: boolean;
  @ApiPropertyOptional() @IsOptional() @IsDateString() startDate?: string | null;
  @ApiPropertyOptional() @IsOptional() @IsDateString() completionDate?: string | null;

  @ApiPropertyOptional({
    description:
      'Gán / đổi / gỡ CĐT (DEVELOPER user id). Chỉ admin được đổi; null để gỡ.',
  })
  @IsOptional() @IsString() ownerId?: string | null;
}
