# [DEF:clean_release_dto:Module]
# @TIER: STANDARD
# @PURPOSE: Data Transfer Objects for clean release compliance subsystem.
# @LAYER: Application

from datetime import datetime
from typing import List, Optional, Dict, Any
from pydantic import BaseModel, Field
from src.services.clean_release.enums import CandidateStatus, RunStatus, ComplianceDecision

class CandidateDTO(BaseModel):
    """DTO for ReleaseCandidate."""
    id: str
    version: str
    source_snapshot_ref: str
    build_id: Optional[str] = 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: Optional[str] = None
    declared_category: Optional[str] = None
    source_uri: Optional[str] = None
    source_host: Optional[str] = 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: Optional[ComplianceDecision] = None
    report_id: Optional[str] = None
    task_id: Optional[str] = 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: Optional[str] = None
    latest_manifest_digest: Optional[str] = None
    latest_run_id: Optional[str] = None
    latest_run_status: Optional[RunStatus] = None
    latest_report_id: Optional[str] = None
    latest_report_final_status: Optional[ComplianceDecision] = None
    latest_policy_snapshot_id: Optional[str] = None
    latest_policy_version: Optional[str] = None
    latest_registry_snapshot_id: Optional[str] = None
    latest_registry_version: Optional[str] = None
    latest_approval_decision: Optional[str] = None
    latest_publication_id: Optional[str] = None
    latest_publication_status: Optional[str] = None

# [/DEF:clean_release_dto:Module]