"""
Base blueprint interface for build plan generation.
"""

from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from typing import Optional
from pathlib import Path


@dataclass
class BuildPlan:
    """A build plan containing all information needed to build and deploy."""
    
    framework: str
    language: str
    package_manager: str
    dependency_file: str
    build_command: Optional[str] = None
    start_command: Optional[str] = None
    port: int = 8000
    dockerfile: Optional[str] = None
    env_vars: dict = field(default_factory=dict)
    detected_from: str = "unknown"  # How the framework was detected
    
    def to_dict(self) -> dict:
        """Convert build plan to dictionary."""
        return {
            "framework": self.framework,
            "language": self.language,
            "package_manager": self.package_manager,
            "dependency_file": self.dependency_file,
            "build_command": self.build_command,
            "start_command": self.start_command,
            "port": self.port,
            "dockerfile": self.dockerfile,
            "env_vars": self.env_vars,
            "detected_from": self.detected_from,
        }


class Blueprint(ABC):
    """
    Abstract base class for deployment blueprints.
    
    Blueprints analyze project structure and generate build plans.
    """
    
    name: str = "base"
    languages: list[str] = []
    
    @abstractmethod
    def detect(self, project_path: Path) -> bool:
        """
        Detect if this blueprint applies to the given project.
        
        Args:
            project_path: Path to the project directory
            
        Returns:
            True if this blueprint can handle the project
        """
        pass
    
    @abstractmethod
    def generate_plan(self, project_path: Path) -> BuildPlan:
        """
        Generate a build plan for the project.
        
        Args:
            project_path: Path to the project directory
            
        Returns:
            BuildPlan with all build/deployment information
        """
        pass
    
    def get_priority(self) -> int:
        """
        Get the priority of this blueprint (higher = tried first).
        
        Returns:
            Priority integer
        """
        return 100
