from __future__ import annotations

from typing import Literal

from pydantic import BaseModel, ConfigDict

from app.rda.domain.fhir_validation import RdaValidationResult
from app.rda.domain.models import RdaArtifact, RdaArtifactType, RdaGenerationStatus, RdaJobState


class ApplicationModel(BaseModel):
    model_config = ConfigDict(extra="forbid", str_strip_whitespace=True)


class GenerateRdaCommand(ApplicationModel):
    username: str
    case_key: str
    artifact_type: RdaArtifactType
    force: bool = False
    persist: bool = True


class GeneratedRdaArtifact(RdaArtifact):
    stored: bool = True
    source: Literal["generated", "cache"]


class RdaGenerationResult(GeneratedRdaArtifact):
    """Nombre explícito del resultado de generación para contratos externos."""


class QueuedRdaGeneration(ApplicationModel):
    case_key: str
    artifact_type: RdaArtifactType
    job_id: str
    status: RdaJobState
    reused: bool = False


class RdaStatusResult(RdaGenerationStatus):
    source: Literal["status", "artifact"] = "status"


class RdaValidationReviewResult(ApplicationModel):
    case_key: str
    artifact_type: RdaArtifactType
    artifact: RdaArtifact | None = None
    status: RdaStatusResult | None = None
    validation: RdaValidationResult | None = None
