# coding=utf-8

from django.conf import settings

from rest_framework import serializers

from utils.exceptions import CustomError

from apps.base import Formater
from apps.images.models import Images

from .models import VhicleDriveReserve

class VhicleDriveReserveSerializer(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')
    img1_url = serializers.SerializerMethodField()
    img2_url = serializers.SerializerMethodField()

    def get_img1_url(self, obj):
        if obj.img1:
            return '%s%s' % (settings.MEDIA_URL, obj.img1.picture)
        return ''

    def get_img2_url(self, obj):
        if obj.img2:
            return '%s%s' % (settings.MEDIA_URL, obj.img2.picture)
        return ''

    class Meta:
        model = VhicleDriveReserve
        fields = '__all__'

