import { ApiProperty } from '@nestjs/swagger';
import { IsBoolean, IsEnum, ValidateIf } from 'class-validator';
import { Transform } from 'class-transformer';
import { FilterQueueEntity } from 'src/modules/queue/domain/entities/filter.entity';
import { ORDER_TYPE } from 'src/core/strings/constants/base.constants';

export class QueueDto implements FilterQueueEntity {
  @ApiProperty({
    isArray: true,
    required: false,
  })
  // @IsString()
  @ValidateIf((body) => body.status)
  @Transform(({ value }) => {
    if (!value) return [];
    return Array.isArray(value) ? value : [value];
  })
  status: string[];

  @ApiProperty({ type: Boolean, required: false })
  @Transform((body) => body.value == 'true')
  @IsBoolean()
  @ValidateIf((body) => body.vip)
  vip: boolean;

  @ApiProperty({ type: String, required: false })
  order_by: string;

  @ApiProperty({
    type: 'string',
    required: false,
    description: `Select ("${ORDER_TYPE.ASC}", "${ORDER_TYPE.DESC}")`,
  })
  @ValidateIf((body) => body.order_type)
  @IsEnum(ORDER_TYPE, {
    message: `order_type must be a valid enum ${JSON.stringify(
      Object.values(ORDER_TYPE),
    )}`,
  })
  order_type: ORDER_TYPE;
}
