import {
  IsString,
  IsBoolean,
  IsObject,
  IsOptional,
  MaxLength,
  MinLength,
} from 'class-validator';
import { ApiPropertyOptional } from '@nestjs/swagger';

/**
 * DTO for updating an existing integration credential
 * Note: Integration type cannot be changed after creation
 */
export class UpdateCredentialDto {
  @ApiPropertyOptional({
    description: 'Human-readable name for this credential configuration',
    example: 'Production PlentyOne API v2',
    minLength: 3,
    maxLength: 100,
  })
  @IsString()
  @IsOptional()
  @MinLength(3)
  @MaxLength(100)
  name?: string;

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

  @ApiPropertyOptional({
    description: 'Whether this credential is active',
    example: true,
  })
  @IsBoolean()
  @IsOptional()
  isActive?: boolean;

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