from api_graphql.abc.mutation_abc import MutationABC
from api_graphql.require_any_resolvers import has_assigned_user_spaces
from api_graphql.service.query_context import QueryContext
from service.permission.permissions_enum import Permissions


class Mutation(MutationABC):
    def __init__(self):
        MutationABC.__init__(self, "")

        self.add_mutation_type(
            "apiKey",
            "ApiKey",
            require_any_permission=[
                Permissions.api_keys_create,
                Permissions.api_keys_update,
                Permissions.api_keys_delete,
            ],
        )
        self.add_mutation_type(
            "role",
            "Role",
            require_any_permission=[
                Permissions.roles_create,
                Permissions.roles_update,
                Permissions.roles_delete,
            ],
        )
        self.add_mutation_type(
            "user",
            "User",
            require_any_permission=[
                Permissions.users_update,
                Permissions.users_delete,
            ],
        )

        self.add_mutation_type(
            "domain",
            "Domain",
            require_any_permission=[
                Permissions.domains_create,
                Permissions.domains_update,
                Permissions.domains_delete,
            ],
        )
        self.add_mutation_type(
            "userSpace",
            "UserSpace",
            require_any=(
                [
                    Permissions.user_spaces_create,
                    Permissions.user_spaces_update,
                    Permissions.user_spaces_delete,
                ],
                [lambda ctx: True],
            ),
        )
        self.add_mutation_type(
            "group",
            "Group",
            require_any=(
                [
                    Permissions.groups_create,
                    Permissions.groups_update,
                    Permissions.groups_delete,
                ],
                [has_assigned_user_spaces],
            ),
        )
        self.add_mutation_type(
            "shortUrl",
            "ShortUrl",
            require_any=(
                [
                    Permissions.short_urls_create,
                    Permissions.short_urls_update,
                    Permissions.short_urls_delete,
                ],
                [has_assigned_user_spaces],
            ),
        )

        self.add_mutation_type(
            "setting",
            "Setting",
            require_any_permission=[
                Permissions.settings_update,
            ],
        )
        self.add_mutation_type(
            "userSetting",
            "UserSetting",
        )
        self.add_mutation_type(
            "featureFlag",
            "FeatureFlag",
            require_any_permission=[
                Permissions.administrator,
            ],
        )
        self.add_mutation_type(
            "privacy",
            "Privacy",
        )
