import { ApiProperty } from '@nestjs/swagger';
import {
  ArrayMinSize,
  IsArray,
  IsInt,
  IsOptional,
  Min,
  ValidateNested,
} from 'class-validator';
import { Type } from 'class-transformer';

export class BatchCreateItemDto {
  @ApiProperty()
  @IsInt()
  @Min(1)
  originGoodId!: number;

  @ApiProperty({ required: false })
  @IsOptional()
  @IsInt()
  @Min(0)
  priority?: number;
}

export class BatchCreateGoodDto {
  @ApiProperty({ type: [BatchCreateItemDto] })
  @IsArray()
  @ArrayMinSize(1)
  @ValidateNested({ each: true })
  @Type(() => BatchCreateItemDto)
  items!: BatchCreateItemDto[];

  @ApiProperty()
  @IsInt()
  @Min(1)
  countryId!: number;

  @ApiProperty()
  @IsInt()
  @Min(1)
  categoryId!: number;

  @ApiProperty({ required: false, nullable: true, type: [Number] })
  @IsOptional()
  @IsArray()
  @IsInt({ each: true })
  @Min(1, { each: true })
  tagIds?: number[];

  @ApiProperty({ required: false, nullable: true })
  @IsOptional()
  @IsInt()
  @Min(1)
  positionId?: number;

  @ApiProperty({ required: false, default: 0 })
  @IsOptional()
  @IsInt()
  @Min(0)
  defaultPriority?: number;
}