from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework.reverse import reverse
from rest_framework import serializers
from rest_framework import generics
from rest_framework import status
from core.models import *
from django.forms import widgets
from services.vtr.models import VTRTenant, VTRService
from services.volt.models import CordSubscriberRoot
from xos.apibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView, XOSPermissionDenied
from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField
from django.contrib.contenttypes.models import ContentType

def get_default_vtr_service():
    vtr_services = VTRService.get_service_objects().all()
    if vtr_services:
        return vtr_services[0]
    return None

class VTRTenantForAPI(VTRTenant):
    class Meta:
        proxy = True
        app_label = "cord"

class VTRTenantSerializer(PlusModelSerializer):
        id = ReadOnlyField()
        target_id = serializers.IntegerField()
        test = serializers.CharField()
        scope = serializers.CharField()
        argument = serializers.CharField(required=False)
        provider_service = serializers.PrimaryKeyRelatedField(queryset=VTRService.get_service_objects().all(), default=get_default_vtr_service)
        result = serializers.CharField(required=False)
        result_code = serializers.CharField(required=False)
        backend_status = ReadOnlyField()

        humanReadableName = serializers.SerializerMethodField("getHumanReadableName")
        is_synced = serializers.SerializerMethodField("isSynced")

        class Meta:
            model = VTRTenantForAPI
            fields = ('humanReadableName', 'id', 'provider_service', 'target_id', 'scope', 'test', 'argument', 'result', 'result_code', 'is_synced', 'backend_status' )

        def getHumanReadableName(self, obj):
            return obj.__unicode__()

        def isSynced(self, obj):
            return (obj.enacted is not None) and (obj.enacted >= obj.updated)

        def create(self, validated_data):
            # force the target_type to be CordSubscriberRoot
            validated_data["target_type_id"] = ContentType.objects.get_for_model(CordSubscriberRoot).id
            return super(VTRTenantSerializer, self).create(validated_data)

class TruckRollViewSet(XOSViewSet):
    base_name = "truckroll"
    method_name = "truckroll"
    method_kind = "viewset"
    queryset = VTRTenantForAPI.get_tenant_objects().all() # select_related().all()
    serializer_class = VTRTenantSerializer

    @classmethod
    def get_urlpatterns(self, api_path="^"):
        patterns = super(TruckRollViewSet, self).get_urlpatterns(api_path=api_path)

        return patterns

    def list(self, request):
        queryset = self.filter_queryset(self.get_queryset())

        serializer = self.get_serializer(queryset, many=True)

        return Response(serializer.data)

