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

export class CreateIndustrialParkDto {
  @ApiProperty({ example: 'KCN VSIP Hải Phòng', description: 'Tên KCN' })
  @IsString()
  @MaxLength(200)
  name!: string;

  @ApiPropertyOptional({ example: 'VSIP Hai Phong Industrial Park' })
  @IsOptional()
  @IsString()
  nameEn?: string;

  @ApiProperty({ example: 'vsip-hai-phong', description: 'URL slug (unique)' })
  @IsString()
  @MaxLength(100)
  slug!: string;

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

  @ApiPropertyOptional({ example: 'VSIP Joint Venture' })
  @IsOptional()
  @IsString()
  operator?: string;

  @ApiProperty({ enum: IndustrialParkStatus, example: 'OPERATIONAL' })
  @IsEnum(IndustrialParkStatus)
  status!: IndustrialParkStatus;

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

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

  @ApiProperty({ example: 'Phường Đông Hải, Quận Hải An' })
  @IsString()
  address!: string;

  @ApiProperty({ example: 'Hải An' })
  @IsString()
  district!: string;

  @ApiProperty({ example: 'Hải Phòng' })
  @IsString()
  province!: string;

  @ApiProperty({ enum: VietnamRegion, example: 'NORTH' })
  @IsEnum(VietnamRegion)
  region!: VietnamRegion;

  @ApiProperty({ example: 1200, description: 'Tổng diện tích (ha)' })
  @IsNumber()
  @Type(() => Number)
  @Min(0)
  totalAreaHa!: number;

  @ApiProperty({ example: 900, description: 'Diện tích cho thuê (ha)' })
  @IsNumber()
  @Type(() => Number)
  @Min(0)
  leasableAreaHa!: number;

  @ApiProperty({ example: 75, description: 'Tỷ lệ lấp đầy (0-100)' })
  @IsNumber()
  @Type(() => Number)
  @Min(0)
  @Max(100)
  occupancyRate!: number;

  @ApiProperty({ example: 225, description: 'Diện tích còn trống (ha)' })
  @IsNumber()
  @Type(() => Number)
  @Min(0)
  remainingAreaHa!: number;

  @ApiPropertyOptional({ example: 150 })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  @Min(0)
  tenantCount?: number;

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

  @ApiPropertyOptional({ example: 80, description: 'Giá thuê đất (USD/m²/năm)' })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  landRentUsdM2Year?: number;

  @ApiPropertyOptional({ example: 5.0, description: 'Giá thuê nhà xưởng xây sẵn (USD/m²/tháng)' })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  rbfRentUsdM2Month?: number;

  @ApiPropertyOptional({ example: 4.0, description: 'Giá thuê kho xây sẵn (USD/m²/tháng)' })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  rbwRentUsdM2Month?: number;

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

  @ApiPropertyOptional({ description: 'Hạ tầng kỹ thuật' })
  @IsOptional()
  @IsObject()
  infrastructure?: Record<string, unknown>;

  @ApiPropertyOptional({ description: 'Kết nối giao thông' })
  @IsOptional()
  @IsObject()
  connectivity?: Record<string, unknown>;

  @ApiPropertyOptional({ description: 'Ưu đãi đầu tư' })
  @IsOptional()
  @IsObject()
  incentives?: Record<string, unknown>;

  @ApiProperty({ example: ['electronics', 'logistics'], description: 'Ngành mục tiêu' })
  @IsArray()
  @IsString({ each: true })
  targetIndustries!: string[];

  @ApiPropertyOptional({ description: 'Mô tả (tiếng Việt)' })
  @IsOptional()
  @IsString()
  description?: string;

  @ApiPropertyOptional({ description: 'Mô tả (tiếng Anh)' })
  @IsOptional()
  @IsString()
  descriptionEn?: string;
}
