import {
  IsInt,
  IsOptional,
  IsString,
  ValidatorConstraint,
  ValidatorConstraintInterface,
  ValidationArguments,
} from 'class-validator';

@ValidatorConstraint({ name: 'onlyOne', async: false })
export class OnlyOneIdConstraint implements ValidatorConstraintInterface {
  validate(_: any, args: ValidationArguments) {
    const obj = args.object as any;
    return (
      (!!obj.set_id && !obj.contract_id) || (!obj.set_id && !!obj.contract_id)
    );
  }

  defaultMessage(args: ValidationArguments) {
    return 'Either set_id or contract_id must be provided, but not both';
  }
}

export class RemoveAttachmentDto {
  @IsString()
  id: string;

  @IsOptional()
  @IsInt()
  set_id?: number;

  @IsOptional()
  @IsInt()
  contract_id?: number;

  @IsString()
  file_name: string;

  @IsString()
  file_url: string;
}
