"""Persistence errors.

Stable exceptions for persistence operations. Transports and higher layers
can handle these without depending on storage implementations.
"""

from __future__ import annotations

from dataclasses import dataclass
from typing import Any


@dataclass
class PersistenceError(Exception):
    """Base error for persistence operations."""

    message: str = "persistence_error"

    def __str__(self) -> str:
        return str(self.message or self.__class__.__name__)


@dataclass
class NotFoundError(PersistenceError):
    """Entity not found (workspace/folder/document/revision)."""

    message: str = "not_found"


@dataclass
class ValidationError(PersistenceError):
    """Input/content validation failed."""

    message: str = "validation_error"


@dataclass
class ConflictError(PersistenceError):
    """Conflict (typically optimistic concurrency / base revision mismatch)."""

    message: str = "conflict"
    doc_id: str | None = None
    base_rev: str | None = None
    head_rev: str | None = None
    head_content: Any | None = None
    conflict_code: str | None = None


__all__ = [
    "ConflictError",
    "NotFoundError",
    "PersistenceError",
    "ValidationError",
]
