# альтернативная тренировочная версия, удалить этот файл пред выгрузкой!!!


# import graphene
# import graphql_jwt


# class Mutation(graphene.ObjectType):
#     token_auth = graphql_jwt.ObtainJSONWebToken.Field()
#     verify_token = graphql_jwt.Verify.Field()
#     refresh_token = graphql_jwt.Refresh.Field()


# schema = graphene.Schema(mutation=Mutation)

import graphene
import graphql_jwt
from wagtail.api.v2.views import PagesAPIViewSet
from wagtail.api.v2.router import WagtailAPIRouter
from wagtail.api.v2.utils import BadRequestError
from wagtail.models import Page
from wagtail.users.models import UserProfile
from graphene_django import DjangoObjectType
# from graphql_jwt.refresh_token.shortcuts import RefreshTokenMutation

class UserType(DjangoObjectType):
    class Meta:
        model = UserProfile
        fields = "__all__"

class PageType(DjangoObjectType):
    class Meta:
        model = Page
        fields = "__all__"
        
        
class ObtainJSONWebToken(graphql_jwt.JSONWebTokenMutation):
    user = graphene.Field(UserType)

    @classmethod
    def resolve(cls, root, info, **kwargs):
        return cls(user=info.context.user)

# class RefreshMutation(graphql_jwt.Refresh):
#     user = graphene.Field(UserType)

#     @classmethod
#     def resolve(cls, root, info, **kwargs):
#         return cls(user=info.context.user)

# class RevokeMutation(graphql_jwt.RevokeMutation):
#     user = graphene.Field(UserType)

#     @classmethod
#     def resolve(cls, root, info, **kwargs):
#         return cls(user=info.context.user)

class Mutation(graphene.ObjectType):
    token_auth = ObtainJSONWebToken.Field()
    verify_token = graphql_jwt.Verify.Field()
    # refresh_token = RefreshMutation.Field()
    refresh_token = graphql_jwt.Refresh.Field()
    # revoke_token = RevokeMutation.Field()

router = WagtailAPIRouter('wagtailapi')
router.register_endpoint('pages', PagesAPIViewSet)

class Query(graphene.ObjectType):
    pages = graphene.List(PageType)

    def resolve_pages(self, info):
        return Page.objects.live().public()

schema = graphene.Schema(query=Query, mutation=Mutation)
