"""Piggie exception hierarchy."""

from __future__ import annotations


class PiggieError(Exception):
    """Base exception for all Piggie errors."""


class ConnectionError(PiggieError):
    """Failed to connect to PostgreSQL or set up AGE/pgvector."""


class CypherError(PiggieError):
    """Error executing a Cypher query."""


class AgtypeParseError(PiggieError):
    """Failed to parse an agtype value from PostgreSQL."""

    def __init__(self, raw_value: str, cause: Exception | None = None) -> None:
        self.raw_value = raw_value
        self.cause = cause
        msg = f"Failed to parse agtype: {raw_value!r}"
        if cause:
            msg += f" ({cause})"
        super().__init__(msg)


class VectorError(PiggieError):
    """Error in vector search or index operations."""


class SchemaError(PiggieError):
    """Error in schema introspection or graph management."""


class BulkLoadError(PiggieError):
    """Error during bulk node/edge loading."""


class BuilderError(PiggieError):
    """Error building a Cypher query."""


class AlgorithmError(PiggieError):
    """Error running a graph algorithm."""


class IntegrationError(PiggieError):
    """Error in a third-party integration (NetworkX, LangChain, etc.)."""


class LabelError(PiggieError):
    """Invalid Cypher label or relationship type name."""
