"""Result wrappers for Admiral API responses."""


class SolveResult:
    """Result from a solve operation."""
    def __init__(self, data=None):
        data = data or {}
        self.solution = data.get("solution")
        self.energy = data.get("energy", data.get("score", float("inf")))
        self.solver = data.get("solver", "auto")
        self.time_ms = data.get("time_ms", 0)
        self.convergence = data.get("convergence", [])
        self.feasible = data.get("feasible", None)
        self.reads = data.get("reads", 0)
        self.race_metadata = data.get("race_metadata")
        self._raw = data

    def __repr__(self):
        return f"SolveResult(energy={self.energy}, solver={self.solver}, time_ms={self.time_ms:.1f})"


class AnalysisResult:
    """Result from AI Advisor analysis."""
    def __init__(self, data=None):
        data = data or {}
        self.problem_type = data.get("problem_type")
        self.structure = data.get("structure", {})
        self.complexity = data.get("complexity")
        self.estimated_time = data.get("estimated_solve_time_seconds")
        self.recommendations = data.get("recommendations", [])
        self.suggested_config = data.get("suggested_config", {})
        self.race_recommended = data.get("race_recommended", False)
        self._raw = data

    def __repr__(self):
        top = self.recommendations[0]["solver"] if self.recommendations else "auto"
        return f"AnalysisResult(complexity={self.complexity}, top_solver={top})"


class FormulationResult:
    """Result from NL Builder formulation."""
    def __init__(self, data=None):
        data = data or {}
        self.problem_type = data.get("problem_type")
        self.data = data.get("data", {})
        self.config = data.get("config", {})
        self.explanation = data.get("explanation", {})
        self.method = data.get("formulation_method", "template")
        self.model = data.get("model_used")
        self._raw = data

    def __repr__(self):
        return f"FormulationResult(type={self.problem_type}, method={self.method})"


class DetectionResult:
    """Result from auto-detection."""
    def __init__(self, data=None):
        data = data or {}
        self.detected_type = data.get("detected_type")
        self.confidence = data.get("confidence", 0)
        self.reason = data.get("reason", "")
        self.alternatives = data.get("alternatives", [])
        self._raw = data

    def __repr__(self):
        return f"DetectionResult(type={self.detected_type}, confidence={self.confidence:.0%})"
