"""Diarization domain ports and error hierarchy."""

from __future__ import annotations


class DiarizationError(Exception):
    """Base exception for diarization errors."""


class JobNotFoundError(DiarizationError):
    """Diarization job not found."""

    def __init__(self, job_id: str) -> None:
        """Initialize with job ID.

        Args:
            job_id: The job ID that was not found.
        """
        self.job_id = job_id
        super().__init__(f"Diarization job not found: {job_id}")


class JobAlreadyActiveError(DiarizationError):
    """A diarization job is already running for this meeting."""

    def __init__(self, meeting_id: str, existing_job_id: str) -> None:
        """Initialize with meeting and existing job IDs.

        Args:
            meeting_id: The meeting ID.
            existing_job_id: The ID of the already-active job.
        """
        self.meeting_id = meeting_id
        self.existing_job_id = existing_job_id
        super().__init__(
            f"Diarization already in progress for meeting {meeting_id} "
            f"(job: {existing_job_id})"
        )


class CancellationError(DiarizationError):
    """Failed to cancel diarization job."""

    def __init__(self, job_id: str, reason: str) -> None:
        """Initialize with job ID and reason.

        Args:
            job_id: The job ID that could not be cancelled.
            reason: The reason cancellation failed.
        """
        self.job_id = job_id
        self.reason = reason
        super().__init__(f"Failed to cancel job {job_id}: {reason}")


class AudioNotFoundError(DiarizationError):
    """Meeting has no audio file for diarization."""

    def __init__(self, meeting_id: str) -> None:
        """Initialize with meeting ID.

        Args:
            meeting_id: The meeting ID with missing audio.
        """
        self.meeting_id = meeting_id
        super().__init__(f"No audio file for meeting: {meeting_id}")


class EngineNotReadyError(DiarizationError):
    """Diarization engine is not initialized."""

    def __init__(self, reason: str = "Engine not loaded") -> None:
        """Initialize with reason.

        Args:
            reason: Why the engine is not ready.
        """
        self.reason = reason
        super().__init__(f"Diarization engine not ready: {reason}")
