"""
Module Settings — Domain Exceptions

خطاهای اختصاصی سیستم تنظیمات.
"""
from shared.exceptions.base import NexaException, NotFoundException, ValidationException


class SettingsException(NexaException):
    """خطای پایه تنظیمات."""

    message = "خطا در سیستم تنظیمات"
    code = "SETTINGS_ERROR"
    http_status = 400


class ModuleSchemaNotRegistered(SettingsException):
    """Schema ماژول ثبت نشده است."""

    code = "MODULE_SCHEMA_NOT_REGISTERED"
    http_status = 404

    def __init__(self, module_key: str, **kwargs):
        message = f"Schema for module '{module_key}' is not registered"
        super().__init__(
            message=message,
            details={"module_key": module_key},
            **kwargs,
        )


class SettingsNotFoundException(NotFoundException):
    """تنظیمات ماژول یافت نشد."""

    def __init__(self, module_key: str, **kwargs):
        super().__init__(
            resource="ModuleSettings",
            identifier=module_key,
            **kwargs,
        )


class SettingsValidationError(ValidationException):
    """خطای اعتبارسنجی تنظیمات."""

    code = "SETTINGS_VALIDATION_ERROR"

    def __init__(self, message: str | None = None, errors: dict | None = None, **kwargs):
        super().__init__(
            message=message or "تنظیمات ارائه‌شده معتبر نیست",
            errors=errors,
            **kwargs,
        )


class InvalidSettingsPath(SettingsException):
    """مسیر تنظیم نامعتبر است."""

    code = "INVALID_SETTINGS_PATH"

    def __init__(self, path: str, module_key: str, **kwargs):
        message = f"Invalid settings path '{path}' for module '{module_key}'"
        super().__init__(
            message=message,
            details={"path": path, "module_key": module_key},
            **kwargs,
        )
