from typing import Self

from ariadne.types import Resolver

from api_graphql.abc.field_builder_abc import FieldBuilderABC
from api_graphql.field.resolver_field import ResolverField


class ResolverFieldBuilder(FieldBuilderABC):

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

        self._resolver = None
        self._direct_result = False

    def with_resolver(self, resolver: Resolver) -> Self:
        assert resolver is not None, "resolver cannot be None"
        self._resolver = resolver
        return self

    def with_direct_result(self) -> Self:
        self._direct_result = True
        return self

    def build(self) -> ResolverField:
        assert self._resolver is not None, "resolver cannot be None"
        return ResolverField(
            self._name,
            self._require_any_permission,
            self._require_any,
            self._public,
            self._resolver,
            self._direct_result,
        )
