# Path: coaster/sqlalchemy/annotations.py
# def _configure_annotations(mapper_, cls):
# def annotation_wrapper(annotation, doc=None):
#     def decorator(attr):


from sqlalchemy import event, inspect
from sqlalchemy.orm.attributes import NEVER_SET, NO_VALUE
from .annotations import annotation_wrapper, annotations_configured
__all__ = ['immutable', 'cached', 'ImmutableColumnError']


immutable = annotation_wrapper(
    'immutable',
    "Marks a column as immutable once set. "
    "Only blocks direct changes; columns may still be updated via relationships or SQL",
)
cached = annotation_wrapper(
    'cached', "Marks the column's contents as a cached value from another source"
)


class ImmutableColumnError(AttributeError):
    """Exception raised when an immutable column is set."""

    def __init__(self, class_name, column_name, old_value, new_value, message=None):
        """Create exception."""
        if message is None:
            message = (
                f"Cannot update column {class_name}.{column_name} from {old_value!r} to"
                f" {new_value!r}: column is immutable."
            )
        super().__init__(message)
        self.class_name = class_name
        self.column_name = column_name
        self.old_value = old_value
        self.new_value = new_value



# Path: coaster/sqlalchemy/annotations.py
# def _configure_annotations(mapper_, cls):
# def annotation_wrapper(annotation, doc=None):
#     def decorator(attr):


# Path: coaster/sqlalchemy/immutable_annotation.py
from sqlalchemy import event, inspect
from sqlalchemy.orm.attributes import NEVER_SET, NO_VALUE
from .annotations import annotation_wrapper, annotations_configured

__all__ = ['immutable', 'cached', 'ImmutableColumnError']


immutable = annotation_wrapper(
    'immutable',
    "Marks a column as immutable once set. "
    "Only blocks direct changes; columns may still be updated via relationships or SQL",
)
cached = annotation_wrapper(
    'cached', "Marks the column's contents as a cached value from another source"
)


class ImmutableColumnError(AttributeError):
    """Exception raised when an immutable column is set."""

    def __init__(self, class_name, column_name, old_value, new_value, message=None):
        """Create exception."""
        if message is None:
            message = (
                f"Cannot update column {class_name}.{column_name} from {old_value!r} to"
                f" {new_value!r}: column is immutable."
            )
        super().__init__(message)
        self.class_name = class_name
        self.column_name = column_name
        self.old_value = old_value
        self.new_value = new_value



@annotations_configured.connect