from rest_framework import serializers

from fwd_api.models import SubscriptionRequest, Subscription

from fwd_api.utils.DateUtil import FORMAT


class SubscriptionResponse(serializers.Serializer):
    id = serializers.IntegerField(read_only=True)
    current_token = serializers.IntegerField(required=False)
    limit_token = serializers.IntegerField(required=False)
    start_at = serializers.DateTimeField(required=False, format=FORMAT.DD_MM_YYYY_HHMMSS.value)
    expired_at = serializers.DateTimeField(required=False, format=FORMAT.DD_MM_YYYY_HHMMSS.value)
    plan_code = serializers.SerializerMethodField()

    def create(self, validated_data):
        """
        Create and return a new `Snippet` instance, given the validated data.
        """
        return SubscriptionRequest.objects.create(**validated_data)

    def update(self, instance, validated_data):
        return instance

    def get_plan_code(self, obj: Subscription):
        return obj.pricing_plan.code




