# app/modules/prospecting/schemas/score.py
"""Pydantic schemas for opportunity scoring."""

import json
from datetime import datetime

from pydantic import BaseModel, field_validator


class ProspectScoreResponse(BaseModel):
    """Schema for prospect score response."""

    id: int
    prospect_id: int
    score: int
    technical_health_score: int
    modernity_score: int
    business_value_score: int
    engagement_score: int
    reason_flags: list[str] = []
    score_breakdown: dict[str, dict[str, int]] | None = None
    lead_tier: str | None = None
    notes: str | None = None
    created_at: datetime
    updated_at: datetime

    @field_validator("reason_flags", mode="before")
    @classmethod
    def parse_reason_flags(cls, v):
        if isinstance(v, str):
            return json.loads(v)
        return v

    @field_validator("score_breakdown", mode="before")
    @classmethod
    def parse_score_breakdown(cls, v):
        if isinstance(v, str):
            return json.loads(v)
        return v

    class Config:
        from_attributes = True
