"""Compatibility wrapper for legacy production_workflow imports."""

from typing import Any, Dict, List, Optional

from .workflow_engine import get_workflow


class ProductionWorkflow:
    """Expose the legacy API expected by server.py."""

    def __init__(self):
        self._workflow = get_workflow()

    def __getattr__(self, name):
        return getattr(self._workflow, name)

    def generate_song(self, genre: str = "reggaeton", bpm: float = 95.0, key: str = "Am",
                      style: str = "classic", structure: str = "standard") -> Dict[str, Any]:
        return self._workflow.generate_complete_reggaeton(
            bpm=bpm, key=key, style=style, structure=structure
        )

    def generate_from_samples(self, samples: Optional[List[Dict[str, Any]]] = None,
                              bpm: float = 95.0, key: str = "Am",
                              style: str = "matched") -> Dict[str, Any]:
        result = self._workflow.generate_complete_reggaeton(
            bpm=bpm, key=key, style=style, structure="standard", use_samples=bool(samples)
        )
        if isinstance(result, dict):
            result.setdefault("input_samples", samples or [])
        return result

    def produce_reggaeton(self, bpm: float = 95.0, key: str = "Am",
                          style: str = "classic", structure: str = "verse-chorus") -> Dict[str, Any]:
        return self._workflow.generate_complete_reggaeton(
            bpm=bpm, key=key, style=style, structure=structure
        )

    def produce_from_reference(self, reference_path: str, bpm: Optional[float] = None,
                               key: Optional[str] = None) -> Dict[str, Any]:
        result = self._workflow.generate_from_reference(reference_path)
        if isinstance(result, dict):
            if bpm is not None:
                result.setdefault("requested_bpm", bpm)
            if key is not None:
                result.setdefault("requested_key", key)
        return result

    def produce_arrangement(self, bpm: float = 95.0, key: str = "Am",
                            style: str = "classic") -> Dict[str, Any]:
        result = self._workflow.generate_complete_reggaeton(
            bpm=bpm, key=key, style=style, structure="extended"
        )
        if isinstance(result, dict):
            result.setdefault("view", "Arrangement")
        return result

    def complete_production(self, bpm: float = 95.0, key: str = "Am",
                            style: str = "classic") -> Dict[str, Any]:
        result = self._workflow.generate_complete_reggaeton(
            bpm=bpm, key=key, style=style, structure="extended"
        )
        if isinstance(result, dict):
            result.setdefault("production_complete", True)
        return result
