import { IsString, IsUUID, IsOptional, IsBoolean, MaxLength, MinLength } from 'class-validator';

/**
 * DTO para crear un nuevo certificado CSD
 * Note: CertificateType enum removed per DDL alignment (fiscal schema has no certificate_type column)
 */
export class CreateCertificateDto {
  @IsUUID()
  tenantId: string;

  @IsString()
  @MinLength(12)
  @MaxLength(13)
  rfc: string;

  @IsString()
  @MaxLength(20)
  certificateNumber: string;

  @IsString()
  certificatePem: string;

  @IsString()
  privateKeyPem: string;

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

  @IsString()
  @IsOptional()
  @MaxLength(255)
  description?: string;

  @IsString()
  @IsOptional()
  notes?: string;
}

/**
 * DTO para actualizar un certificado
 */
export class UpdateCertificateDto {
  @IsBoolean()
  @IsOptional()
  isDefault?: boolean;

  @IsString()
  @IsOptional()
  privateKeyPem?: string;

  @IsString()
  @IsOptional()
  keyPassword?: string;
}

/**
 * DTO para filtrar certificados
 */
export class CertificateFilterDto {
  @IsUUID()
  @IsOptional()
  tenantId?: string;

  @IsString()
  @IsOptional()
  rfc?: string;

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

  @IsBoolean()
  @IsOptional()
  isDefault?: boolean;
}

/**
 * DTO de respuesta de certificado (sin datos sensibles)
 */
export class CertificateResponseDto {
  id: string;
  tenantId: string;
  rfc: string;
  certificateNumber: string;
  serialNumber: string;
  issuedAt: Date;
  expiresAt: Date;
  status: string;
  issuerName: string | null;
  subjectName: string | null;
  description: string | null;
  isDefault: boolean;
  createdAt: Date;
  updatedAt: Date | null;
}
