"""Shared protocol definitions for project gRPC mixins."""

from __future__ import annotations

from typing import TYPE_CHECKING, Protocol, Self

if TYPE_CHECKING:
    from noteflow.application.services.project_service import ProjectService
    from noteflow.domain.ports.repositories.identity import (
        ProjectMembershipRepository,
        ProjectRepository,
        WorkspaceRepository,
    )
    from noteflow.domain.ports.unit_of_work import UnitOfWork


class ProjectRepositoryProvider(Protocol):
    """Repository provider protocol for project operations."""

    supports_projects: bool
    supports_workspaces: bool
    projects: ProjectRepository
    project_memberships: ProjectMembershipRepository
    workspaces: WorkspaceRepository

    async def commit(self) -> None: ...

    async def __aenter__(self) -> Self: ...

    async def __aexit__(
        self,
        exc_type: type[BaseException] | None,
        exc_val: BaseException | None,
        exc_tb: object,
    ) -> None: ...


class ProjectServicer(Protocol):
    """Protocol for hosts that support project operations."""

    project_service: ProjectService | None

    def create_repository_provider(self) -> ProjectRepositoryProvider | UnitOfWork: ...
