/**
 * Adapter interface contracts for infrastructure providers
 * This defines the unified interface that all adapters must implement
 */

import { ResourceProvider } from '../types/resource.js'

export interface NormalizedResource {
  id: string
  name: string
  type: string
  provider: ResourceProvider
  providerId: string
  providerResourceId?: string
  region?: string
  status: string
  metadata: Record<string, any>
  tags: string[]
  createdAt: Date
  updatedAt: Date
}

export interface NormalizedMetrics {
  resourceId: string
  metricType: string
  value: number
  timestamp: Date
  labels?: Record<string, string>
}

export interface NormalizedRelationship {
  sourceId: string
  targetId: string
  type: string
  metadata?: Record<string, any>
}

/**
 * Base adapter interface that all provider adapters must implement
 */
export interface InfrastructureAdapter {
  /**
   * Unique identifier for the adapter
   */
  readonly provider: ResourceProvider

  /**
   * Discover and return all resources from the provider
   */
  discoverResources(): Promise<NormalizedResource[]>

  /**
   * Get a specific resource by provider ID
   */
  getResource(providerId: string): Promise<NormalizedResource | null>

  /**
   * Create a new resource
   */
  createResource(spec: ResourceSpec): Promise<NormalizedResource>

  /**
   * Update an existing resource
   */
  updateResource(providerId: string, spec: Partial<ResourceSpec>): Promise<NormalizedResource>

  /**
   * Delete a resource
   */
  deleteResource(providerId: string): Promise<boolean>

  /**
   * Get metrics for a resource
   */
  getMetrics(providerId: string, timeRange: TimeRange): Promise<NormalizedMetrics[]>

  /**
   * Get resource relationships/dependencies
   */
  getRelationships(providerId: string): Promise<NormalizedRelationship[]>

  /**
   * Health check for the adapter/provider connection
   */
  healthCheck(): Promise<HealthStatus>
}

export interface ResourceSpec {
  name: string
  type: string
  region?: string
  config: Record<string, any>
  tags?: string[]
}

export interface TimeRange {
  start: Date
  end: Date
}

export interface HealthStatus {
  status: 'healthy' | 'degraded' | 'unhealthy'
  message?: string
  lastChecked: Date
}

