"""Analyze type definitions."""

from __future__ import annotations

from datetime import datetime
from typing import Any

from pydantic import BaseModel, ConfigDict, Field

from .common import ConfidenceLevel, PersonalityDimensions


class DimensionConfidence(BaseModel):
    """Confidence information for a single dimension."""

    level: str
    score: float
    signal_agreement: float = Field(alias="signalAgreement")

    model_config = ConfigDict(populate_by_name=True)


class AnalysisResult(BaseModel):
    """Result from personality analysis."""

    model_config = ConfigDict(populate_by_name=True)

    scores: PersonalityDimensions
    confidence: ConfidenceLevel | None = None
    method: str
    text_length: int = Field(alias="textLength")
    analyzed_at: datetime = Field(alias="analyzedAt")
    dimension_confidence: dict[str, DimensionConfidence] | None = Field(
        default=None, alias="dimensionConfidence"
    )
    signal_breakdown: dict[str, Any] | None = Field(
        default=None, alias="signalBreakdown"
    )


class BatchAnalysisItem(BaseModel):
    """A single item in batch analysis results."""

    model_config = ConfigDict(populate_by_name=True)

    id: str
    scores: PersonalityDimensions | None = None
    confidence: ConfidenceLevel | None = None
    method: str | None = None
    text_length: int | None = Field(default=None, alias="textLength")
    dimension_confidence: dict[str, DimensionConfidence] | None = Field(
        default=None, alias="dimensionConfidence"
    )
    error: str | None = None


class BatchAnalysisSummary(BaseModel):
    """Summary of batch analysis."""

    total: int
    success: int
    errors: int


class BatchAnalysisResult(BaseModel):
    """Result from batch personality analysis."""

    model_config = ConfigDict(populate_by_name=True)

    results: list[BatchAnalysisItem]
    summary: BatchAnalysisSummary
    analyzed_at: datetime = Field(alias="analyzedAt")
