import {
  IsString,
  IsOptional,
  IsBoolean,
  IsInt,
  Min,
  MaxLength,
  Matches,
  IsUrl,
} from 'class-validator';
import { Type } from 'class-transformer';
import { COMPANY_ID_PATTERN } from '../error-codes';

export class CreatePartnerDto {
  @IsString()
  @MaxLength(64)
  @Matches(COMPANY_ID_PATTERN, {
    message: 'companyId must match [a-z0-9_-]+',
  })
  companyId!: string;

  @IsString()
  @MaxLength(200)
  companyLabel!: string;

  @IsOptional()
  @IsString()
  @MaxLength(200)
  displayLabel?: string;

  @IsUrl({ protocols: ['http', 'https'], require_protocol: true })
  @MaxLength(1000)
  targetUrl!: string;

  @IsOptional()
  @IsBoolean()
  isActive?: boolean;

  @IsOptional()
  @IsInt()
  @Type(() => Number)
  sortOrder?: number;
}

export class UpdatePartnerDto {
  @IsOptional()
  @IsString()
  @MaxLength(64)
  @Matches(COMPANY_ID_PATTERN)
  companyId?: string;

  @IsOptional()
  @IsString()
  @MaxLength(200)
  companyLabel?: string;

  @IsOptional()
  @IsString()
  @MaxLength(200)
  displayLabel?: string;

  @IsOptional()
  @IsUrl({ protocols: ['http', 'https'], require_protocol: true })
  @MaxLength(1000)
  targetUrl?: string;

  @IsOptional()
  @IsBoolean()
  isActive?: boolean;

  @IsOptional()
  @IsInt()
  @Type(() => Number)
  sortOrder?: number;
}

export class DispatchChoiceDto {
  @IsString()
  @MaxLength(64)
  companyId!: string;

  @IsOptional()
  @IsString()
  @MaxLength(32)
  partnerId?: string;
}

export class DispatchRequestDto {
  @IsString()
  @MaxLength(32)
  checkpointCode!: string;

  @IsString()
  qrToken!: string;

  @IsOptional()
  choice?: DispatchChoiceDto;
}

export class ValidateTicketRequestDto {
  @IsString()
  ticket!: string;

  @IsString()
  @MaxLength(32)
  targetCheckpointCode!: string;
}
