"""
Base registry interface and configuration.

This module defines the common interface that all registry implementations must follow.
"""

from abc import ABC, abstractmethod
from pathlib import Path
from typing import Dict, List, Optional, Any
from dataclasses import dataclass


@dataclass
class RegistryConfig:
    """Base configuration for package registries."""
    name: str
    type: str
    url: str
    auth_token_env: Optional[str] = None

    def get_auth_token(self) -> Optional[str]:
        """Get authentication token from environment variable."""
        if self.auth_token_env:
            import os
            return os.getenv(self.auth_token_env)
        return None


class RegistryInterface(ABC):
    """Abstract interface for package registries."""

    def __init__(self, config: RegistryConfig):
        """Initialize the registry with configuration."""
        self.config = config

    @abstractmethod
    def upload_package(self, package_path: Path, dry_run: bool = False) -> bool:
        """Upload a package to the registry.

        Args:
            package_path: Path to package file (.whl or .tar.gz)
            dry_run: If True, show what would be done without uploading

        Returns:
            True if upload successful, False otherwise
        """
        pass

    @abstractmethod
    def check_auth(self) -> bool:
        """Check if authentication is properly configured.

        Returns:
            True if authenticated, False otherwise
        """
        pass

    @abstractmethod
    def list_packages(self) -> List[Dict[str, Any]]:
        """List packages in the registry.

        Returns:
            List of package information dictionaries
        """
        pass

    @abstractmethod
    def get_package_info(self, package_name: str) -> Optional[Dict[str, Any]]:
        """Get information about a specific package.

        Args:
            package_name: Name of the package

        Returns:
            Package information dictionary or None if not found
        """
        pass

    @abstractmethod
    def delete_package_version(self, package_name: str, version: str,
                              dry_run: bool = False) -> bool:
        """Delete a specific version of a package.

        Args:
            package_name: Name of the package
            version: Version to delete
            dry_run: If True, show what would be done without deleting

        Returns:
            True if deletion successful, False otherwise
        """
        pass

    @abstractmethod
    def get_registry_info(self) -> Dict[str, Any]:
        """Get information about the registry configuration.

        Returns:
            Dictionary with registry information
        """
        pass