# #region clean_release_dto [C:3] [TYPE Module] [SEMANTICS pydantic, clean-release, dto, schema, transfer]
# @BRIEF Data Transfer Objects for clean release compliance subsystem.
# @LAYER Application
# @RELATION DEPENDS_ON -> [EXT:Library:pydantic]

from datetime import datetime
from typing import Any

from pydantic import BaseModel, Field

from src.services.clean_release.enums import CandidateStatus, ComplianceDecision, RunStatus


class CandidateDTO(BaseModel):
    """DTO for ReleaseCandidate."""
    id: str
    version: str
    source_snapshot_ref: str
    build_id: str | None = None
    created_at: datetime
    created_by: str
    status: CandidateStatus

class ArtifactDTO(BaseModel):
    """DTO for CandidateArtifact."""
    id: str
    candidate_id: str
    path: str
    sha256: str
    size: int
    detected_category: str | None = None
    declared_category: str | None = None
    source_uri: str | None = None
    source_host: str | None = None
    metadata: dict[str, Any] = Field(default_factory=dict)

class ManifestDTO(BaseModel):
    """DTO for DistributionManifest."""
    id: str
    candidate_id: str
    manifest_version: int
    manifest_digest: str
    artifacts_digest: str
    created_at: datetime
    created_by: str
    source_snapshot_ref: str
    content_json: dict[str, Any]

class ComplianceRunDTO(BaseModel):
    """DTO for ComplianceRun status tracking."""
    run_id: str
    candidate_id: str
    status: RunStatus
    final_status: ComplianceDecision | None = None
    report_id: str | None = None
    task_id: str | None = None

class ReportDTO(BaseModel):
    """Compact report view."""
    report_id: str
    candidate_id: str
    final_status: ComplianceDecision
    policy_version: str
    manifest_digest: str
    violation_count: int
    generated_at: datetime

class CandidateOverviewDTO(BaseModel):
    """Read model for candidate overview."""
    candidate_id: str
    version: str
    source_snapshot_ref: str
    status: CandidateStatus
    latest_manifest_id: str | None = None
    latest_manifest_digest: str | None = None
    latest_run_id: str | None = None
    latest_run_status: RunStatus | None = None
    latest_report_id: str | None = None
    latest_report_final_status: ComplianceDecision | None = None
    latest_policy_snapshot_id: str | None = None
    latest_policy_version: str | None = None
    latest_registry_snapshot_id: str | None = None
    latest_registry_version: str | None = None
    latest_approval_decision: str | None = None
    latest_publication_id: str | None = None
    latest_publication_status: str | None = None

# #endregion clean_release_dto
