from typing import Union, Type, Optional, Callable

from api_graphql.abc.collection_filter_abc import CollectionFilterABC
from api_graphql.abc.field_abc import FieldABC
from api_graphql.abc.filter_abc import FilterABC
from api_graphql.typing import TRequireAny
from core.database.abc.data_access_object_abc import DataAccessObjectABC
from core.typing import T
from service.permission.permissions_enum import Permissions


class DaoField(FieldABC):

    def __init__(
        self,
        name: str,
        require_any_permission: list[Permissions] = None,
        require_any: TRequireAny = None,
        public: bool = False,
        dao: DataAccessObjectABC = None,
        filter_type: Type[FilterABC] = None,
        default_filter: Callable = None,
        sort_type: Type[T] = None,
        direct_result: bool = False,
    ):
        FieldABC.__init__(self, name, require_any_permission, require_any, public)
        self._name = name

        self._public = public
        self._dao = dao
        self._filter_type = filter_type
        self._default_filter = default_filter
        self._sort_type = sort_type
        self._direct_result = direct_result

    @property
    def dao(self) -> Optional[DataAccessObjectABC]:
        return self._dao

    @property
    def filter_type(
        self,
    ) -> Optional[Type[FilterABC]]:
        return self._filter_type

    @property
    def default_filter(self) -> Optional[Callable]:
        return self._default_filter

    @property
    def sort_type(self) -> Optional[Type[T]]:
        return self._sort_type

    @property
    def direct_result(self) -> bool:
        return self._direct_result
