from rest_framework.decorators import api_view, authentication_classes, permission_classes
from rest_framework.authentication import SessionAuthentication, TokenAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework import status

from core.models.Subscription import Subscription
from core.models.TeamMember import TeamMember
from core.serializers.SubscriptionSerializer import SubscriptionSerializer


from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema



@api_view(['GET'])
@authentication_classes([SessionAuthentication, TokenAuthentication])
@permission_classes([IsAuthenticated])
def get_user_subscriptions(request):
    user = request.user
    subscriptions = Subscription.objects.filter(user=user).order_by('-startTime')
    serializer = SubscriptionSerializer(subscriptions, many=True)
    return Response({
        'status': 200,
        'subscriptions': serializer.data,
        'message': 'موفق'
    }, status=status.HTTP_200_OK)
