import { ApiProperty } from '@nestjs/swagger';
import {
  IsArray,
  IsNotEmpty,
  IsNumber,
  IsString,
  Matches,
  Min,
  ValidateNested,
} from 'class-validator';

export class ItemSplitQueueDto {
  @ApiProperty({ name: 'queue_item_id', required: true })
  @IsString()
  @IsNotEmpty()
  queue_item_id: string;
  @ApiProperty({
    type: Number,
    required: true,
    example: 1,
  })
  @IsNumber()
  @Min(1)
  @IsNotEmpty()
  qty: number;
}

export class SplitQueueDto {
  @ApiProperty({ name: 'order_id', required: true })
  @IsString()
  @IsNotEmpty()
  order_id: string;

  @ApiProperty({ name: 'name', required: true })
  @IsString()
  @IsNotEmpty()
  name: string;

  @ApiProperty({
    name: 'phone',
    required: true,
    description: 'Phone Number Must Start With 62, no + or 0',
    example: '+628123456789',
  })
  @IsString()
  @IsNotEmpty()
  @Matches(/^\+628\d+$/i, { message: 'Nomor Telepon tidak valid' })
  phone: string;

  @ApiProperty({
    type: [ItemSplitQueueDto],
    required: false,
    example: [
      {
        queue_item_id: 'string',
        qty: 1,
      },
    ],
  })
  @ValidateNested({ each: true })
  @IsArray()
  items: ItemSplitQueueDto[];
}
