import { Transform, Type } from 'class-transformer';
import {
  ArrayMaxSize,
  IsArray,
  IsBoolean,
  IsEnum,
  IsNotEmpty,
  IsNumber,
  IsOptional,
  IsString,
  MaxLength,
  Min,
} from 'class-validator';
import { MarketplaceListingCondition } from '../enums/marketplace-listing-condition.enum';
import { MarketplaceListingCategory } from '../enums/marketplace-listing-category.enum';
import { toStringArray } from '../../../common/utils/array-transform.util';
import { toBoolean } from '../../../common/utils/query-transform.util';

export class CreateInstrumentDto {
  @IsString()
  @IsNotEmpty()
  @MaxLength(120)
  title!: string;

  @IsOptional()
  @IsString()
  @MaxLength(2000)
  description?: string;

  @Type(() => Number)
  @IsNumber()
  @Min(0)
  price!: number;

  @IsOptional()
  @IsString()
  @MaxLength(8)
  currency?: string;

  @Type(() => Number)
  @IsNumber()
  @Min(0)
  quantity!: number;

  @IsOptional()
  @Transform(toStringArray)
  @IsArray()
  @ArrayMaxSize(5)
  @IsString({ each: true })
  imageUrls?: string[];

  @IsOptional()
  @Transform(toBoolean)
  @IsBoolean()
  isActive?: boolean;

  @IsOptional()
  @IsEnum(MarketplaceListingCondition)
  condition?: MarketplaceListingCondition;

  @IsOptional()
  @IsString()
  @MaxLength(80)
  instrumentType?: string;

  @IsOptional()
  @IsEnum(MarketplaceListingCategory)
  listingCategory?: MarketplaceListingCategory;
}
