"""
Interface for connection orchestration services.

Defines the contract for connection management including validation,
auto-creation, and recreation operations across organizations.
"""

from abc import ABC, abstractmethod
from typing import Dict, List, Any
from ..models import ConnectionValidationResult, UploadConfig


class ConnectionOrchestratorInterface(ABC):
    """
    Interface for connection orchestration operations.
    
    Handles connection validation, auto-creation, and recreation
    for CloudZero billing connections across multiple organizations.
    """
    
    @abstractmethod
    def ensure_connections_exist(
        self,
        organization: str,
        providers: List[str],
        s3_config: Dict[str, str]
    ) -> ConnectionValidationResult:
        """
        Ensure all required connections exist for an organization.
        
        Validates existing connections and auto-creates missing ones.
        
        Args:
            organization: Organization name
            providers: List of provider names requiring connections
            s3_config: S3 configuration for connection creation
            
        Returns:
            ConnectionValidationResult with validation and creation outcomes
        """
        pass
    
    @abstractmethod
    def validate_connection_status(
        self,
        organization: str,
        providers: List[str]
    ) -> ConnectionValidationResult:
        """
        Validate connection status without creating new connections.
        
        Args:
            organization: Organization name
            providers: List of provider names to validate
            
        Returns:
            ConnectionValidationResult with validation status
        """
        pass
    
    @abstractmethod
    def recreate_organization_connections(
        self,
        organization: str,
        providers: List[str],
        s3_config: Dict[str, str],
        dry_run: bool = False
    ) -> Dict[str, Any]:
        """
        Recreate all connections for an organization.
        
        Deletes existing connections and S3 data, then creates new connections.
        
        Args:
            organization: Organization name
            providers: List of provider names
            s3_config: S3 configuration for new connections
            dry_run: If True, only show what would be done
            
        Returns:
            Recreation result with deleted and created connection details
        """
        pass
    
    @abstractmethod
    def validate_api_credentials(self, organization: str) -> bool:
        """
        Validate API credentials for an organization.
        
        Args:
            organization: Organization name
            
        Returns:
            True if credentials are valid, False otherwise
        """
        pass
    
    @abstractmethod
    def get_organization_api_key(self, organization: str) -> str:
        """
        Get API key for an organization.
        
        Handles org-specific keys and fallback to generic key.
        
        Args:
            organization: Organization name
            
        Returns:
            API key for the organization
            
        Raises:
            ConnectionOrchestratorError: If no API key found
        """
        pass
    
    @abstractmethod
    def list_organization_connections(
        self,
        organization: str,
        providers: List[str] = None
    ) -> Dict[str, List[Dict[str, Any]]]:
        """
        List existing connections for an organization.
        
        Args:
            organization: Organization name
            providers: Optional list to filter by providers
            
        Returns:
            Dict mapping provider names to list of connection details
        """
        pass