"""
Common schemas used across endpoints
"""

from pydantic import BaseModel, Field
from typing import List, Dict, Any


class HealthResponse(BaseModel):
    """Health check response"""

    model_config = {
        "protected_namespaces": (),  # Allow fields starting with "model_"
        "json_schema_extra": {
            "example": {
                "status": "healthy",
                "model_loaded": True,
                "adapters_loaded": []
            }
        }
    }

    status: str = Field(..., description="Service status")
    model_loaded: bool = Field(..., description="Whether base model is loaded")
    adapters_loaded: List[str] = Field(..., description="List of loaded LoRA adapters")


class ErrorResponse(BaseModel):
    """Error response"""

    model_config = {
        "json_schema_extra": {
            "example": {
                "error": "Prediction failed",
                "detail": "Model not loaded properly"
            }
        }
    }

    error: str = Field(..., description="Error message")
    detail: str = Field(None, description="Detailed error information")


class PredictionResponse(BaseModel):
    """
    Unified prediction response for both influencer and business predictions

    This schema is used by both /predict/influencer and /predict/business endpoints
    """

    model_config = {
        "json_schema_extra": {
            "example": {
                "niche_probabilities": {
                    "Fashion": 0.85,
                    "Lifestyle": 0.10,
                    "Beauty": 0.05
                },
                "popularity_probabilities": {
                    "Micro": 0.90,
                    "Nano": 0.05,
                    "Mid": 0.05
                },
                "processed_data": {
                    "top_niche": "Fashion",
                    "top_popularity": "Micro"
                }
            }
        }
    }

    niche_probabilities: Dict[str, float] = Field(
        ...,
        description="Probability distribution across niche classes"
    )
    popularity_probabilities: Dict[str, float] = Field(
        ...,
        description="Probability distribution across popularity tiers"
    )
    processed_data: Dict[str, Any] = Field(
        ...,
        description="Snapshot of processed data for transparency"
    )

