import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

/**
 * Represents the status of a single integration
 */
export class IntegrationStatusDto {
  @ApiProperty({
    description: 'Integration type identifier',
    example: 'plentyone',
  })
  type: string;

  @ApiProperty({
    description: 'Display name of the integration',
    example: 'PlentyONE',
  })
  name: string;

  @ApiProperty({
    description: 'Whether the integration is properly configured',
    example: true,
  })
  configured: boolean;

  @ApiProperty({
    description: 'Whether the integration is currently connected/healthy',
    example: true,
  })
  connected: boolean;

  @ApiPropertyOptional({
    description: 'Last successful connection time',
    example: '2024-01-15T10:30:00Z',
  })
  lastChecked?: string;

  @ApiPropertyOptional({
    description: 'Response latency in milliseconds',
    example: 245,
  })
  latencyMs?: number;

  @ApiPropertyOptional({
    description: 'Error message if connection failed',
    example: 'Authentication failed: Invalid API key',
  })
  error?: string;

  @ApiPropertyOptional({
    description: 'Missing configuration items',
    example: ['PLENTYONE_CLIENT_ID', 'PLENTYONE_CLIENT_SECRET'],
    type: [String],
  })
  missingConfig?: string[];
}

/**
 * Response containing all integration statuses
 */
export class IntegrationsOverviewDto {
  @ApiProperty({
    description: 'List of all integration statuses',
    type: [IntegrationStatusDto],
  })
  integrations: IntegrationStatusDto[];

  @ApiProperty({
    description: 'Number of configured integrations',
    example: 2,
  })
  configuredCount: number;

  @ApiProperty({
    description: 'Number of connected integrations',
    example: 2,
  })
  connectedCount: number;

  @ApiProperty({
    description: 'Total number of available integrations',
    example: 3,
  })
  totalCount: number;
}

/**
 * Response for health check of a specific integration
 */
export class IntegrationHealthDto {
  @ApiProperty({
    description: 'Integration type identifier',
    example: 'zulip',
  })
  type: string;

  @ApiProperty({
    description: 'Whether the connection test was successful',
    example: true,
  })
  healthy: boolean;

  @ApiProperty({
    description: 'Health check message',
    example: 'Successfully connected to ZULIP',
  })
  message: string;

  @ApiPropertyOptional({
    description: 'Response latency in milliseconds',
    example: 123,
  })
  latencyMs?: number;

  @ApiProperty({
    description: 'Timestamp of the health check',
    example: '2024-01-15T10:30:00Z',
  })
  timestamp: string;

  @ApiPropertyOptional({
    description: 'Additional details about the connection',
    example: { zulipVersion: '8.0', featureLevel: 200 },
  })
  details?: Record<string, unknown>;
}
