"""Safe public errors for external data-source operations."""


class DataSourceError(RuntimeError):
    code = "DATASOURCE_ERROR"
    http_status = 500
    default_message = "data source operation failed"

    def __init__(self, message=None):
        super().__init__(message or self.default_message)


class DataSourceNotFound(DataSourceError):
    code = "DATASOURCE_NOT_FOUND"
    http_status = 404
    default_message = "data source was not found"


class DataSourceTypeUnsupported(DataSourceError):
    code = "DATASOURCE_TYPE_UNSUPPORTED"
    http_status = 400
    default_message = "data source type is not supported"


class DataSourceConfigurationInvalid(DataSourceError):
    code = "DATASOURCE_CONFIGURATION_INVALID"
    http_status = 400
    default_message = "data source configuration is invalid"


class DataSourceCredentialUnavailable(DataSourceError):
    code = "DATASOURCE_CREDENTIAL_UNAVAILABLE"
    http_status = 503
    default_message = "data source credential is unavailable"


class DataSourceConnectionFailed(DataSourceError):
    code = "DATASOURCE_CONNECTION_FAILED"
    http_status = 503
    default_message = "data source connection failed"


class DataSourcePoolTimeout(DataSourceError):
    code = "DATASOURCE_POOL_TIMEOUT"
    http_status = 503
    default_message = "data source connection pool timed out"


class DataSourceCircuitOpen(DataSourceError):
    code = "DATASOURCE_CIRCUIT_OPEN"
    http_status = 503
    default_message = "data source circuit is open"


class DataSourceQueryTimeout(DataSourceError):
    code = "DATASOURCE_QUERY_TIMEOUT"
    http_status = 504
    default_message = "data source query timed out"


class DataSourceReadOnlyViolation(DataSourceError):
    code = "DATASOURCE_READ_ONLY_VIOLATION"
    http_status = 409
    default_message = "data source operation violates read-only policy"
