from rest_framework import serializers
from datetime import datetime, timedelta
from rates.models import RateLists, Daytimes

class UserSerializer(serializers.Serializer):
    name = serializers.CharField()
    mobile = serializers.CharField()


class TripsSerializer(serializers.Serializer):
    id = serializers.IntegerField()
    vehicle_model_name = serializers.CharField()
    vehicle_type_name = serializers.CharField()
    transmission_type_name = serializers.CharField()
    trip_type = serializers.IntegerField()
    uniform_type = serializers.IntegerField()
    pickup_address = serializers.CharField()
    pickup_latitude = serializers.CharField()
    pickup_longitude = serializers.CharField()
    destination_address = serializers.CharField()
    destination_latitude = serializers.CharField()
    destination_longitude = serializers.CharField()
    start_date_time = serializers.SerializerMethodField()
    end_date_time = serializers.SerializerMethodField()
    station_type = serializers.IntegerField()
    instructions = serializers.CharField()
    status = serializers.IntegerField()
    created_at = serializers.DateTimeField()

    def get_start_date_time(self, obj):
        if obj.trip_start_date == None:
            if obj.edit_start_date == None:
                if obj.start_date == None:
                    return None
                else:
                    return (str(obj.start_date) +' '+ obj.start_time)
            else:
                return (str(obj.edit_start_date) +' '+ obj.edit_start_time)
        else:
            return (str(obj.trip_start_date) +' '+obj.trip_start_time)
        
    
    def get_end_date_time(self, obj):
        if obj.trip_end_date == None:
            if obj.edit_end_date == None:
                if obj.end_date == None:
                    return None
                else:
                    return (str(obj.end_date) +' '+ obj.end_time)
            else:
                return (str(obj.edit_end_date) +' '+ obj.edit_end_time)
        else:
            return (str(obj.trip_end_date) +' '+obj.trip_end_time)


    

class TripSerializer(serializers.Serializer):
    id = serializers.IntegerField()
    vehicle_model_name = serializers.CharField()
    vehicle_type_name = serializers.CharField()
    transmission_type_name = serializers.CharField()
    vehicle_model_id = serializers.IntegerField()
    vehicle_type_id = serializers.IntegerField()
    transmission_type_id = serializers.IntegerField()
    trip_type = serializers.IntegerField()
    uniform_type = serializers.IntegerField()
    pickup_address = serializers.CharField()
    pickup_latitude = serializers.CharField()
    pickup_longitude = serializers.CharField()
    destination_address = serializers.CharField()
    destination_latitude = serializers.CharField()
    destination_longitude = serializers.CharField()
    start_date_time = serializers.SerializerMethodField()
    end_date_time = serializers.SerializerMethodField()
    station_type = serializers.IntegerField()
    instructions = serializers.CharField()
    amount  = serializers.IntegerField()
    net_amount  = serializers.IntegerField()
    status = serializers.IntegerField()
    created_at = serializers.DateTimeField()
    driver = UserSerializer(many=False)

    def get_start_date_time(self, obj):
        if obj.trip_start_date == None:
            if obj.edit_start_date == None:
                if obj.start_date == None:
                    return None
                else:
                    return (str(obj.start_date) +' '+ obj.start_time)
            else:
                return (str(obj.edit_start_date) +' '+ obj.edit_start_time)
        else:
            return (str(obj.trip_start_date) +' '+obj.trip_start_time)
        
    
    def get_end_date_time(self, obj):
        if obj.trip_end_date == None:
            if obj.edit_end_date == None:
                if obj.end_date == None:
                    return None
                else:
                    return (str(obj.end_date) +' '+ obj.end_time)
            else:
                return (str(obj.edit_end_date) +' '+ obj.edit_end_time)
        else:
            return (str(obj.trip_end_date) +' '+obj.trip_end_time)



class TaxSerializer(serializers.Serializer):
    id = serializers.IntegerField()
    title = serializers.CharField()
    tax_percentage = serializers.CharField()