# #region clean_release_mappers [C:3] [TYPE Module] [SEMANTICS clean-release, mapper, dto, entity, transform]
# @BRIEF Map between domain entities (SQLAlchemy models) and DTOs.
# @LAYER Application
# @RELATION DEPENDS_ON -> clean_release_dto

from src.models.clean_release import ComplianceReport, ComplianceRun, DistributionManifest, ReleaseCandidate
from src.services.clean_release.dto import CandidateDTO, ComplianceRunDTO, ManifestDTO, ReportDTO
from src.services.clean_release.enums import CandidateStatus, ComplianceDecision, RunStatus


def map_candidate_to_dto(candidate: ReleaseCandidate) -> CandidateDTO:
    return CandidateDTO(
        id=candidate.id,
        version=candidate.version,
        source_snapshot_ref=candidate.source_snapshot_ref,
        build_id=candidate.build_id,
        created_at=candidate.created_at,
        created_by=candidate.created_by,
        status=CandidateStatus(candidate.status)
    )

def map_manifest_to_dto(manifest: DistributionManifest) -> ManifestDTO:
    return ManifestDTO(
        id=manifest.id,
        candidate_id=manifest.candidate_id,
        manifest_version=manifest.manifest_version,
        manifest_digest=manifest.manifest_digest,
        artifacts_digest=manifest.artifacts_digest,
        created_at=manifest.created_at,
        created_by=manifest.created_by,
        source_snapshot_ref=manifest.source_snapshot_ref,
        content_json=manifest.content_json or {}
    )

def map_run_to_dto(run: ComplianceRun) -> ComplianceRunDTO:
    return ComplianceRunDTO(
        run_id=run.id,
        candidate_id=run.candidate_id,
        status=RunStatus(run.status),
        final_status=ComplianceDecision(run.final_status) if run.final_status else None,
        task_id=run.task_id
    )

def map_report_to_dto(report: ComplianceReport) -> ReportDTO:
    # Note: ReportDTO in dto.py is a compact view
    return ReportDTO(
        report_id=report.id,
        candidate_id=report.candidate_id,
        final_status=ComplianceDecision(report.final_status),
        policy_version="unknown", # Would need to resolve from run/snapshot
        manifest_digest="unknown", # Would need to resolve from run/manifest
        violation_count=0, # Would need to resolve from violations
        generated_at=report.generated_at
    )

# #endregion clean_release_mappers
