# coding=utf-8

from django.conf import settings

from rest_framework import serializers

from .models import VehicleDriveReserve, VehicleInquiry, UsedVehicleInquiry, UsedVehicleEstimate, InsurConsultation

class VehicleDriveReserveSerializer(serializers.ModelSerializer):
    shop_name = serializers.CharField(source='shop.name', read_only=True)
    brand_name = serializers.CharField(source='model.series.brand.name', read_only=True)
    series_name = serializers.CharField(source='model.series.name', read_only=True)
    model_name = serializers.CharField(source='model.name', read_only=True)
    customer_name = serializers.CharField(source='customer.name', read_only=True)
    status_text = serializers.CharField(source='get_status_display', read_only=True)
    create_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M', read_only=True)
    date = serializers.DateField(format='%Y-%m-%d')

    class Meta:
        model = VehicleDriveReserve
        fields = '__all__'


class VehicleInquirySerializer(serializers.ModelSerializer):
    shop_name = serializers.CharField(source='shop.name', read_only=True)
    brand_name = serializers.CharField(source='model.series.brand.name', read_only=True)
    series_name = serializers.CharField(source='model.series.name', read_only=True)
    model_name = serializers.CharField(source='model.name', read_only=True)
    customer_name = serializers.CharField(source='customer.name', read_only=True)
    status_text = serializers.CharField(source='get_status_display', read_only=True)
    create_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M', read_only=True)
    displace_text = serializers.SerializerMethodField()

    def get_displace_text(self, obj):
        return obj.displace and u'是' or u'否'

    class Meta:
        model = VehicleInquiry
        fields = '__all__'


class UsedVehicleInquirySerializer(serializers.ModelSerializer):
    brand_name = serializers.CharField(source='brand.name', read_only=True)
    customer_name = serializers.CharField(source='customer.name', read_only=True)
    customer_tel = serializers.CharField(source='customer.tel', read_only=True)
    status_text = serializers.CharField(source='get_status_display', read_only=True)
    gender_text = serializers.CharField(source='get_gender_display', read_only=True)
    create_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M', read_only=True)

    class Meta:
        model = UsedVehicleInquiry
        fields = '__all__'


class UsedVehicleEstimateSerializer(serializers.ModelSerializer):
    shop_name = serializers.CharField(source='shop.name', read_only=True)
    brand_name = serializers.CharField(source='brand.name', read_only=True)
    customer_name = serializers.CharField(source='customer.name', read_only=True)
    status_text = serializers.CharField(source='get_status_display', read_only=True)
    create_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M', read_only=True)
    plate_date = serializers.DateField(format='%Y-%m-%d')

    class Meta:
        model = UsedVehicleEstimate
        fields = '__all__'


class InsurConsultationSerializer(serializers.ModelSerializer):
    shop_name = serializers.CharField(source='shop.name', read_only=True)
    customer_name = serializers.CharField(source='customer.name', read_only=True)
    status_text = serializers.CharField(source='get_status_display', read_only=True)
    create_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M', read_only=True)

    class Meta:
        model = InsurConsultation
        fields = '__all__'

