"""Unsupported identity repository implementations for memory mode.

Provide repository interfaces that raise NotImplementedError for
operations requiring database persistence.
"""

from __future__ import annotations

from collections.abc import Sequence
from typing import TYPE_CHECKING
from uuid import UUID

_ERR_USERS_DB = "Users require database persistence"
_ERR_WORKSPACES_DB = "Workspaces require database persistence"

if TYPE_CHECKING:
    from noteflow.domain.identity import (
        User,
        Workspace,
        WorkspaceMembership,
        WorkspaceRole,
        WorkspaceSettings,
    )


class UnsupportedUserRepository:
    """User repository that raises for unsupported operations.

    Use in memory mode where users require database persistence.
    """

    async def get(self, user_id: UUID) -> User | None:
        """Not supported in memory mode."""
        raise NotImplementedError(_ERR_USERS_DB)

    async def get_by_email(self, email: str) -> User | None:
        """Not supported in memory mode."""
        raise NotImplementedError(_ERR_USERS_DB)

    async def get_default(self) -> User | None:
        """Not supported in memory mode."""
        raise NotImplementedError(_ERR_USERS_DB)

    async def create(self, user: User) -> User:
        """Not supported in memory mode."""
        raise NotImplementedError(_ERR_USERS_DB)

    async def create_default(
        self,
        user_id: UUID,
        display_name: str,
        email: str | None = None,
    ) -> User:
        """Not supported in memory mode."""
        raise NotImplementedError(_ERR_USERS_DB)

    async def update(self, user: User) -> User:
        """Not supported in memory mode."""
        raise NotImplementedError(_ERR_USERS_DB)

    async def delete(self, user_id: UUID) -> bool:
        """Not supported in memory mode."""
        raise NotImplementedError(_ERR_USERS_DB)


class UnsupportedWorkspaceRepository:
    """Workspace repository that raises for unsupported operations.

    Use in memory mode where workspaces require database persistence.
    """

    async def get(self, workspace_id: UUID) -> Workspace | None:
        """Not supported in memory mode."""
        raise NotImplementedError(_ERR_WORKSPACES_DB)

    async def get_by_slug(self, slug: str) -> Workspace | None:
        """Not supported in memory mode."""
        raise NotImplementedError(_ERR_WORKSPACES_DB)

    async def get_default_for_user(self, user_id: UUID) -> Workspace | None:
        """Not supported in memory mode."""
        raise NotImplementedError(_ERR_WORKSPACES_DB)

    async def create(
        self,
        workspace_id: UUID,
        name: str,
        owner_id: UUID,
        slug: str | None = None,
        is_default: bool = False,
        settings: WorkspaceSettings | None = None,
    ) -> Workspace:
        """Not supported in memory mode."""
        raise NotImplementedError(_ERR_WORKSPACES_DB)

    async def update(self, workspace: Workspace) -> Workspace:
        """Not supported in memory mode."""
        raise NotImplementedError(_ERR_WORKSPACES_DB)

    async def delete(self, workspace_id: UUID) -> bool:
        """Not supported in memory mode."""
        raise NotImplementedError(_ERR_WORKSPACES_DB)

    async def list_for_user(
        self,
        user_id: UUID,
        limit: int = 50,
        offset: int = 0,
    ) -> Sequence[Workspace]:
        """Not supported in memory mode."""
        raise NotImplementedError(_ERR_WORKSPACES_DB)

    async def get_membership(
        self,
        workspace_id: UUID,
        user_id: UUID,
    ) -> WorkspaceMembership | None:
        """Not supported in memory mode."""
        raise NotImplementedError(_ERR_WORKSPACES_DB)

    async def add_member(
        self,
        workspace_id: UUID,
        user_id: UUID,
        role: WorkspaceRole,
    ) -> WorkspaceMembership:
        """Not supported in memory mode."""
        raise NotImplementedError(_ERR_WORKSPACES_DB)

    async def update_member_role(
        self,
        workspace_id: UUID,
        user_id: UUID,
        role: WorkspaceRole,
    ) -> WorkspaceMembership | None:
        """Not supported in memory mode."""
        raise NotImplementedError(_ERR_WORKSPACES_DB)

    async def remove_member(
        self,
        workspace_id: UUID,
        user_id: UUID,
    ) -> bool:
        """Not supported in memory mode."""
        raise NotImplementedError(_ERR_WORKSPACES_DB)

    async def list_members(
        self,
        workspace_id: UUID,
        limit: int = 100,
        offset: int = 0,
    ) -> Sequence[WorkspaceMembership]:
        """Not supported in memory mode."""
        raise NotImplementedError(_ERR_WORKSPACES_DB)
