import { IsString, IsNotEmpty, IsOptional, IsNumber, IsEnum, Min, IsDateString } from 'class-validator';
import { Type, Transform } from 'class-transformer';

export class CreateRoomDto {
  @IsString()
  @IsNotEmpty({ message: '房型名称不能为空' })
  name: string;

  @IsEnum(['hotel', 'homestay', 'apartment', 'hostel'])
  type: 'hotel' | 'homestay' | 'apartment' | 'hostel';

  @IsOptional()
  @IsNumber()
  area?: number;

  @IsOptional()
  @IsString()
  bedType?: string;

  @IsOptional()
  @IsNumber()
  @Min(1)
  maxGuests?: number;

  @IsOptional()
  @IsString()
  floor?: string;

  @IsOptional()
  facilities?: string[];

  @IsOptional()
  images?: string[];

  @IsOptional()
  @IsString()
  coverImage?: string;

  @IsNumber()
  @Min(0)
  price: number;

  @IsOptional()
  description?: string;

  @IsOptional()
  @IsEnum(['free', 'flexible', 'strict'])
  cancelPolicy?: 'free' | 'flexible' | 'strict';
}

export class UpdateRoomDto {
  @IsOptional()
  @IsString()
  name?: string;

  @IsOptional()
  @IsEnum(['hotel', 'homestay', 'apartment', 'hostel'])
  type?: 'hotel' | 'homestay' | 'apartment' | 'hostel';

  @IsOptional()
  @IsNumber()
  area?: number;

  @IsOptional()
  @IsString()
  bedType?: string;

  @IsOptional()
  @IsNumber()
  maxGuests?: number;

  @IsOptional()
  facilities?: string[];

  @IsOptional()
  images?: string[];

  @IsOptional()
  coverImage?: string;

  @IsOptional()
  @IsNumber()
  price?: number;

  @IsOptional()
  @IsEnum(['on_sale', 'off_sale'])
  status?: 'on_sale' | 'off_sale';

  @IsOptional()
  description?: string;
}

export class QueryRoomDto {
  @IsOptional()
  @Type(() => Number)
  page?: number = 1;

  @IsOptional()
  @Type(() => Number)
  pageSize?: number = 10;

  @IsOptional()
  @IsString()
  keyword?: string;

  @IsOptional()
  @IsString()
  type?: string;

  @IsOptional()
  @Type(() => Number)
  minPrice?: number;

  @IsOptional()
  @Type(() => Number)
  maxPrice?: number;

  @IsOptional()
  @IsString()
  city?: string;

  @IsOptional()
  @Type(() => Number)
  merchantId?: number;

  @IsOptional()
  @IsString()
  @Transform(({ value }) => (value === '' ? undefined : value))
  status?: string;

  @IsOptional()
  @IsString()
  auditStatus?: string;

  @IsOptional()
  @IsString()
  sortBy?: string;

  @IsOptional()
  @IsDateString()
  checkIn?: string;

  @IsOptional()
  @IsDateString()
  checkOut?: string;

  @IsOptional()
  @Type(() => Number)
  @Min(1)
  roomCount?: number;

  @IsOptional()
  @Type(() => Number)
  @Min(1)
  adultCount?: number;
}
