import { Product } from '@/entities/product.entity';
import { SystemLang } from '@/system/lang/system.lang';
import { IsUniqueInDatabase } from '@/system/validators/decorators/is-unique-in-database.decorator';
import { Type } from 'class-transformer';
import {
  ArrayNotEmpty,
  IsArray,
  IsNumber,
  IsOptional,
  IsString,
  Min,
} from 'class-validator';

export class CreateProductDto {
  @IsArray()
  @ArrayNotEmpty()
  @IsString({ each: true })
  images: string[];

  @IsString()
  title: string;

  @Type(() => Number) // đảm bảo chuyển đổi từ string -> number khi gửi form-data
  @IsNumber({ maxDecimalPlaces: 2 })
  @Min(0)
  price: number;

  @IsString()
  category: string;

  @IsString()
  condition: string;

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

  @IsString()
  description: string;

  @IsArray()
  @IsString({ each: true })
  @IsOptional()
  tags: string[];

  @IsString()
  @IsUniqueInDatabase(
    Product,
    'sku',
    {},
    {
      message: SystemLang.getCustomText({
        en: 'SKU must be unique',
        vi: 'SKU phải là duy nhất',
      }),
    },
  )
  sku: string;

  @IsOptional()
  @IsString()
  location?: string;
}
