from __future__ import annotations


class AppError(Exception):
    """Base exception for all application errors."""

    def __init__(self, message: str, is_permanent: bool = False) -> None:
        super().__init__(message)
        self.is_permanent = is_permanent


class ValidationError(AppError):
    def __init__(self, message: str) -> None:
        super().__init__(message, is_permanent=True)


class DuplicateMediaError(AppError):
    def __init__(self, existing_job_id: str) -> None:
        super().__init__(f"Duplicate content, existing job: {existing_job_id}", is_permanent=True)
        self.existing_job_id = existing_job_id


class DownloadError(AppError):
    pass


class StorageError(AppError):
    pass


class AIServiceError(AppError):
    pass


class QuotaExceededError(AppError):
    def __init__(self, message: str) -> None:
        super().__init__(message, is_permanent=True)


class InvalidJobTransitionError(AppError):
    def __init__(self, job_id: str, from_status: str, to_status: str) -> None:
        super().__init__(
            f"Job {job_id}: invalid transition {from_status} -> {to_status}",
            is_permanent=True,
        )


class SSRFError(ValidationError):
    pass


class WebhookAuthError(AppError):
    def __init__(self) -> None:
        super().__init__("Invalid webhook secret token", is_permanent=True)
