"""Small compatibility layer for legacy musical_intelligence imports."""

from typing import Any, Dict, List


class MusicalIntelligenceEngine:
    """Expose only the legacy methods still imported by server.py."""

    def __init__(self):
        self._progressions: List[Dict[str, Any]] = []
        self._current_key = "Am"

    def set_multiple_progressions(self, progressions_config: List[Dict[str, Any]]) -> Dict[str, Any]:
        self._progressions = list(progressions_config or [])
        return {
            "sections": [item.get("section", "") for item in self._progressions],
            "progressions": [item.get("progression", "") for item in self._progressions],
            "total_chords": sum(len(str(item.get("progression", "")).split("-")) for item in self._progressions),
        }

    def modulate_key(self, section_index: int, new_key: str) -> Dict[str, Any]:
        original_key = self._current_key
        self._current_key = new_key
        return {
            "original_key": original_key,
            "new_key": new_key,
            "modulation_type": "direct",
            "tracks_affected": [section_index],
        }
