import {
  IsString,
  IsEnum,
  IsNotEmpty,
  IsObject,
  IsOptional,
  MaxLength,
  MinLength,
} from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IntegrationType } from '@prisma/client';

/**
 * DTO for creating a new integration credential
 */
export class CreateCredentialDto {
  @ApiProperty({
    description: 'Type of integration',
    enum: IntegrationType,
    example: IntegrationType.PLENTYONE,
  })
  @IsEnum(IntegrationType)
  @IsNotEmpty()
  type: IntegrationType;

  @ApiProperty({
    description: 'Human-readable name for this credential configuration',
    example: 'Production PlentyOne API',
    minLength: 3,
    maxLength: 100,
  })
  @IsString()
  @IsNotEmpty()
  @MinLength(3)
  @MaxLength(100)
  name: string;

  @ApiProperty({
    description: 'Credential data specific to the integration type',
    example: {
      apiUrl: 'https://api.plentyone.com',
      apiKey: 'secret-api-key',
      username: 'integration-user',
    },
  })
  @IsObject()
  @IsNotEmpty()
  credentials: Record<string, unknown>;

  @ApiPropertyOptional({
    description: 'Optional description for this credential',
    example: 'Main production API access for PlentyOne ERP',
  })
  @IsString()
  @IsOptional()
  @MaxLength(500)
  description?: string;
}
