"""Face verification / liveness stub (SOW proctoring)."""

from app.schemas.common import JobStatus
from app.schemas.face_verification import FaceVerificationRequest, FaceVerificationResponse


class FaceVerificationService:
    async def verify(self, payload: FaceVerificationRequest) -> FaceVerificationResponse:
        # Live CV model wiring comes later; local stub returns conservative scores.
        has_id = bool(payload.id_image_base64)
        has_live = bool(payload.live_image_base64 or payload.idle_image_base64 or payload.source_url)
        match_score = 0.82 if (has_id and has_live) else 0.55 if has_live else 0.4
        liveness = 0.8 if payload.live_image_base64 or payload.source_url else 0.5
        verified = match_score >= 0.75 and liveness >= 0.7
        warnings: list[str] = []
        if not has_id:
            warnings.append("No ID image provided — identity match limited")
        if not payload.live_image_base64 and not payload.source_url:
            warnings.append("No live frame — liveness confidence reduced")
        return FaceVerificationResponse(
            correlation_id=payload.correlation_id,
            interview_id=payload.interview_id,
            status=JobStatus.SUCCEEDED,
            stub=True,
            message="Face verification local stub — wire CV provider for production",
            verified=verified,
            match_score=match_score,
            liveness_score=liveness,
            warnings=warnings,
        )
