from abc import abstractmethod, ABC
from typing import Self

from api_graphql.abc.field_abc import FieldABC
from api_graphql.typing import TRequireAnyPermissions, TRequireAnyResolvers
from service.permission.permissions_enum import Permissions


class FieldBuilderABC(ABC):

    def __init__(self, name: str):
        ABC.__init__(self)

        self._name = name
        self._require_any_permission = None
        self._require_any = None
        self._public = False

    def with_require_any_permission(
        self, require_any_permission: list[Permissions]
    ) -> Self:
        assert (
            require_any_permission is not None
        ), "require_any_permission cannot be None"
        self._require_any_permission = require_any_permission
        return self

    def with_require_any(
        self, permissions: TRequireAnyPermissions, resolvers: TRequireAnyResolvers
    ) -> Self:
        assert permissions is not None, "permissions cannot be None"
        assert resolvers is not None, "resolvers cannot be None"
        self._require_any = (permissions, resolvers)
        return self

    def with_public(self, public: bool = False) -> Self:
        self._public = public
        return self

    @abstractmethod
    def build(self) -> FieldABC:
        pass
