/**
 * Type definitions for Multi-Cloud Orchestration Portal
 */

export interface Environment {
  name: string;
  role: 'admin' | 'workload';
  provider: 'azure' | 'aws' | 'gcp' | 'ibm' | 'oci' | 'onprem';
  type: 'cloud' | 'hci';
  region: string;
  location: string;
  enabled: boolean;
  components: string[];
  infrastructure?: InfrastructureConfig;
  azure?: AzureConfig;
  aws?: AWSConfig;
  gcp?: GCPConfig;
  secrets?: SecretsConfig;
  identity?: IdentityConfig;
  azure_arc?: AzureArcConfig;
  [key: string]: any;
}

export interface InfrastructureConfig {
  kubernetes?: KubernetesConfig;
  networking?: NetworkingConfig;
  storage?: StorageConfig;
}

export interface KubernetesConfig {
  provider: string;
  version: string;
  node_pools?: Record<string, NodePoolConfig>;
  hci?: HCIConfig;
}

export interface NodePoolConfig {
  count: number;
  vm_size?: string;
  instance_type?: string;
  machine_type?: string;
  [key: string]: any;
}

export interface HCIConfig {
  platform: string;
  cluster_name: string;
  node_pools?: Record<string, NodePoolConfig>;
}

export interface NetworkingConfig {
  vpc_cidr?: string;
  vnet_cidr?: string;
  subnets?: SubnetConfig[];
  subnet_cidr?: string;
  gateway?: string;
}

export interface SubnetConfig {
  name: string;
  cidr: string;
  availability_zone?: string;
  region?: string;
}

export interface StorageConfig {
  type?: string;
  volume_size_gb?: number;
  backup_retention_days?: number;
}

export interface AzureConfig {
  resource_group_name?: string;
  subscription_id?: string;
  tenant_id?: string;
  arc_enabled?: boolean;
}

export interface AWSConfig {
  account_id?: string;
  region?: string;
  vpc_id?: string;
}

export interface GCPConfig {
  project_id?: string;
  region?: string;
  zone?: string;
}

export interface SecretsConfig {
  provider: string;
  key_vault_name?: string;
  vault_address?: string;
  region?: string;
}

export interface IdentityConfig {
  provider: string;
  enable_rbac?: boolean;
  federated_identity?: boolean;
  enable_irsa?: boolean;
  workload_identity?: boolean;
  domain?: string;
}

export interface AzureArcConfig {
  enabled: boolean;
  cluster_name: string;
  resource_group?: string;
}

export interface DeploymentStatus {
  status: string;
  last_deployed: string;
  cluster_health: 'healthy' | 'degraded' | 'unhealthy' | 'unknown';
  node_count: number;
  pods_running: number;
  pods_total: number;
  cpu_usage_percent: number;
  memory_usage_percent: number;
  network_in_mbps: number;
  network_out_mbps: number;
  uptime_days: number;
  last_health_check: string;
  total_deployments?: number;
  last_deployment?: string;
}

export interface Metric {
  value: number;
  timestamp: string;
}

export interface Metrics {
  [metricName: string]: Metric[];
}

export interface Alert {
  id: number;
  environment: string;
  severity: 'error' | 'warning' | 'info';
  message: string;
  timestamp: string;
  acknowledged?: boolean;
}

export interface Cost {
  environment: string;
  provider: string;
  cost: number;
  currency: string;
  period_start: string;
  period_end: string;
  resource_type?: string;
}

export interface Deployment {
  id: string;
  environment: string;
  status: string;
  started_at: string;
  completed_at?: string | null;
  triggered_by?: string;
  strategy?: string;
  version?: string;
  logs_path?: string;
}

export interface DeploymentRequest {
  strategy?: string;
  version?: string;
  triggered_by?: string;
}

export interface EnvironmentsConfig {
  environments: Environment[];
  global?: GlobalConfig;
}

export interface GlobalConfig {
  deployment_strategy?: string;
  connectivity?: ConnectivityConfig;
  service_mesh?: ServiceMeshConfig;
  secrets?: SecretsGlobalConfig;
  identity?: IdentityGlobalConfig;
  observability?: ObservabilityConfig;
  cost_optimization?: CostOptimizationConfig;
  security?: SecurityConfig;
}

export interface ConnectivityConfig {
  type: string;
  vpn?: VPNConfig;
  expressroute?: ExpressRouteConfig;
  direct_connect?: DirectConnectConfig;
}

export interface VPNConfig {
  enabled: boolean;
  provider: string;
}

export interface ExpressRouteConfig {
  enabled: boolean;
  provider: string;
}

export interface DirectConnectConfig {
  enabled: boolean;
  provider: string;
}

export interface ServiceMeshConfig {
  enabled: boolean;
  provider: string;
  mTLS?: boolean;
}

export interface SecretsGlobalConfig {
  primary_provider: string;
  vault?: VaultConfig;
}

export interface VaultConfig {
  address: string;
  namespace?: string;
}

export interface IdentityGlobalConfig {
  provider: string;
  federated_identity?: boolean;
  sso_enabled?: boolean;
}

export interface ObservabilityConfig {
  logging?: LoggingConfig;
  metrics?: MetricsConfig;
  tracing?: TracingConfig;
}

export interface LoggingConfig {
  provider: string;
  central_endpoint?: string;
}

export interface MetricsConfig {
  provider: string;
  central_endpoint?: string;
}

export interface TracingConfig {
  provider: string;
  central_endpoint?: string;
}

export interface CostOptimizationConfig {
  enable_spot_instances?: boolean;
  enable_autoscaling?: boolean;
  budget_alerts?: boolean;
}

export interface SecurityConfig {
  zero_trust_networking?: boolean;
  policy_as_code?: boolean;
  enable_network_policies?: boolean;
  enable_pod_security_policies?: boolean;
}

export interface AdminUser {
  id: number;
  username: string;
  email: string;
  role: string;
  created_at: string;
  last_login?: string | null;
  is_active: boolean;
}

export interface ServiceConfig {
  service_name: string;
  enabled: boolean;
  config?: any;
  updated_at: string;
  updated_by?: string | null;
}

export interface ProviderConfig {
  provider_name: string;
  enabled: boolean;
  config?: any;
  updated_at: string;
  updated_by?: string | null;
}

export interface AuditLogEntry {
  id: number;
  admin_user: string;
  action: string;
  resource_type: string;
  resource_id?: string | null;
  details?: string | null;
  ip_address: string;
  timestamp: string;
}

export type ServiceType = 'besu' | 'cacti' | 'firefly' | 'chainlink-ccip';

export interface ServiceMetric {
  id: number;
  service_name: string;
  service_type: ServiceType;
  environment?: string | null;
  metric_name: string;
  metric_value: number;
  metric_unit?: string | null;
  status: 'healthy' | 'degraded' | 'unhealthy' | 'unknown';
  timestamp: string;
  metadata?: any;
}

export interface ServiceStatus {
  status: string;
  lastUpdate: string;
  metrics: Record<string, number>;
}

export interface ServiceHealthSummary {
  total: number;
  healthy: number;
  degraded: number;
  unhealthy: number;
  services: Array<{ name: string; status: string; lastUpdate: string }>;
}

export interface BesuMetrics {
  blockNumber: number;
  peerCount: number;
  syncStatus: 'syncing' | 'synced' | 'behind';
  gasPrice: string;
  networkId: number;
  chainId: number;
  pendingTransactions: number;
  cpuUsage: number;
  memoryUsage: number;
  diskUsage: number;
}

export interface CactiMetrics {
  connectorCount: number;
  activeConnections: number;
  totalTransactions: number;
  pendingTransactions: number;
  failedTransactions: number;
  averageLatency: number;
  cpuUsage: number;
  memoryUsage: number;
}

export interface FireflyMetrics {
  namespaceCount: number;
  activeAPIs: number;
  totalTransactions: number;
  pendingTransactions: number;
  failedTransactions: number;
  averageLatency: number;
  cpuUsage: number;
  memoryUsage: number;
  databaseConnections: number;
}

export interface ChainlinkCCIPMetrics {
  routerAddress: string;
  activeChains: number;
  totalMessages: number;
  pendingMessages: number;
  failedMessages: number;
  averageLatency: number;
  tokenTransfers: number;
  feeTokenBalance: string;
  cpuUsage: number;
  memoryUsage: number;
}

