import { ApiPropertyOptional } from '@nestjs/swagger';
import { Transform, Type } from 'class-transformer';
import {
  IsString,
  IsOptional,
  MinLength,
  IsArray,
  ValidateNested,
  IsInt,
  Min,
} from 'class-validator';

export class MediaOrderItemDto {
  @IsString()
  mediaId!: string;

  @IsInt()
  @Min(0)
  order!: number;
}

export class UpdateListingDto {
  @ApiPropertyOptional({ example: 'Căn hộ 3PN view sông - Vinhomes Central Park', description: 'Listing title (min 5 chars)' })
  @IsOptional()
  @IsString()
  @MinLength(5)
  title?: string;

  @ApiPropertyOptional({ example: 'Căn hộ cao cấp 3 phòng ngủ, nội thất đầy đủ...', description: 'Detailed description (min 10 chars)' })
  @IsOptional()
  @IsString()
  @MinLength(10)
  description?: string;

  @ApiPropertyOptional({ type: String, example: '5500000000', description: 'Price in VND (as string to support bigint)' })
  @IsOptional()
  @Transform(({ value }) => (value != null ? BigInt(value) : undefined))
  priceVND?: bigint;

  @ApiPropertyOptional({ type: String, example: '25000000', description: 'Monthly rent price in VND (as string to support bigint)' })
  @IsOptional()
  @Transform(({ value }) => (value != null ? BigInt(value) : undefined))
  rentPriceMonthly?: bigint;

  @ApiPropertyOptional({ example: ['Hồ bơi', 'Gym', 'Sân chơi trẻ em'], description: 'List of amenities' })
  @IsOptional()
  @IsArray()
  amenities?: string[];

  @ApiPropertyOptional({
    example: [{ mediaId: 'media-1', order: 0 }, { mediaId: 'media-2', order: 1 }],
    description: 'Reorder media items by specifying mediaId and new order',
  })
  @IsOptional()
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => MediaOrderItemDto)
  mediaOrder?: MediaOrderItemDto[];

  // propertyType, address, location CANNOT be changed after ACTIVE status.
}
