"""Abstract base sink for database writers."""

from __future__ import annotations

from abc import ABC, abstractmethod
from typing import Any


class BaseSink(ABC):
    @abstractmethod
    def connect(self) -> None: ...

    @abstractmethod
    def write_batch(self, records: list[dict[str, Any]]) -> None: ...

    @abstractmethod
    def flush(self) -> None: ...

    @abstractmethod
    def close(self) -> None: ...

    def __enter__(self) -> BaseSink:
        self.connect()
        return self

    def __exit__(self, *args: object) -> None:
        self.flush()
        self.close()
