import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
  ArrayMinSize,
  IsArray,
  IsNotEmpty,
  IsOptional,
  IsString,
} from 'class-validator';

/**
 * DTO used to check for duplicate commission contracts.
 *
 * This DTO validates all the necessary fields to identify
 * whether a contract with the given parameters already exists.
 */
export class CheckDuplicateContractDto {
  /**
   * Optional ID of the existing contract (used for updates to exclude self).
   * Example: "contract_123"
   */
  @IsOptional()
  @IsString()
  @ApiPropertyOptional()
  id?: string;

  /**
   * ID of the product associated with the contract.
   * Required field.
   * Example: "prod_101"
   */
  @ApiProperty({ example: 'prod_101', description: 'Selected product ID' })
  @IsString()
  @IsNotEmpty({ message: 'Product is required' })
  product_id: string;

  /**
   * Type of associate (e.g., institute, sub-agent, etc.).
   * Required field.
   * Example: "associate_type"
   */
  @ApiProperty({ example: 'associate_type', description: 'Association type' })
  @IsString()
  @IsNotEmpty({ message: 'Associate is required' })
  association_type: string;

  /**
   * Visa service country ID linked to the contract.
   * Required field.
   * Example: "country_visa_01"
   */
  @ApiProperty({
    example: 'country_visa_01',
    description: 'Visa service country ID',
  })
  @IsString()
  @IsNotEmpty({ message: 'Visa Service is required' })
  visa_service_country_id: string;

  /**
   * Optional associate ID if the contract is associate-specific.
   * Example: "assoc_123"
   */
  @ApiPropertyOptional({ example: 'assoc_123', description: 'Associate ID' })
  @IsString()
  @IsOptional({ message: 'Associate is required' })
  associate_id?: string;

  /**
   * ID of the institute linked to the contract.
   * Required field.
   * Example: "123"
   */
  @ApiProperty({ example: '123', description: 'Institute ID' })
  @IsString()
  @IsNotEmpty({ message: 'Institute is required' })
  institute_id: string;

  /**
   * List of client originating country IDs.
   * Must contain at least one element.
   * Example: ["IN", "AU"]
   */
  @ApiProperty({
    type: [String],
    example: ['IN', 'AU'],
    description: 'Client originating countries',
  })
  @IsArray()
  @ArrayMinSize(1, { message: 'At least one country required' })
  client_from_countries: string[];

  /**
   * Student condition flag (e.g., 1 or 2) for the contract.
   * Required field.
   * Example: "1"
   */
  @ApiProperty({
    example: '1',
    description: 'Student condition flag (e.g., 1 or 2)',
  })
  @IsString()
  @IsNotEmpty({ message: 'Student Condition is required' })
  student_condition: string;
}
