import datetime
from dataclasses import dataclass, field
from typing import List, Literal, Optional
from pydantic import BaseModel, Field


@dataclass
class feature_deps:
    """
    A dataclass to hold feature data dependencies, including a dynamically
    generated current datetime string.

    These deps are used to dynamically provide information to tooling.
    https://ai.pydantic.dev/dependencies/#defining-dependencies

    """

    current_dt: str = field(
        default_factory=lambda: datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
    )
    exclude_osidb_fields: List[str] = field(
        default_factory=list,
    )


class FeatureQueryInput(BaseModel):
    query: str = Field(..., description="General LLM query.")


class AegisFeatureModel(BaseModel):
    """
    Metadata for Aegis features, nested within the main feature model.
    """

    data_quality: Optional[Literal["POOR", "FAIR", "GOOD", "EXCELLENT"]] = Field(
        None,
        description="Overall assessment of the underlying data quality, completeness and internal consistency.",
    )

    confidence: float = Field(
        ...,
        ge=0.0,
        le=1.0,
        description="""
        # Confidence Score Methodology: Quantifying Analytical Reliability

        ## Definition
        A precision-driven numerical representation of analysis reliability, scaled from 0.00 to 1.00, capturing the probabilistic certainty of analytical accuracy.
        """,
    )

    tools_used: List = Field(
        ...,
        description="List the names of registered tools, if any, that was used to formulate this answer. If this is a CVE suggest feature then should minimally include 'osidb_tool'",
    )

    # Important: This default disclaimer is required by AI assessment - do not change or remove without talking to someone !
    disclaimer: Literal[
        "This response was generated by Aegis AI (https://github.com/RedHatProductSecurity/aegis-ai) using generative AI for informational purposes. All findings should be validated by a human expert."
    ]

    def printable_outcome(self) -> str:
        """this method can be overridden to provide printable outcome for logging purposes"""
        return "[...]"


# this is only used by simple_agent
class AegisAnswer(AegisFeatureModel):
    """
    Default answer response.
    """

    explanation: str = Field(
        ...,
        description="A brief rationale explaining how the answer was generated, what sources were primary, and if the answer was provided directly by the LLM or not. Do not repeat the answer here.",
    )

    answer: str = Field(..., description="The direct answer to the user's question.")
