#coding=utf-8
import json
import datetime

from django.db import models
from django.utils import timezone
from django.conf import settings
from apps.foundation.models import Option
from apps.images.models import Images

class UsedVehicle(models.Model):
    STOCK = 0
    SALE = 1
    STATUS_CHOICES = (
        (STOCK, u'在库'),
        (SALE, u'已售'),
    )
    brand = models.ForeignKey(Option, verbose_name=u'品牌', on_delete=models.PROTECT)
    number = models.CharField(max_length=20, verbose_name=u'车牌号')
    model = models.CharField(max_length=200, verbose_name=u'车型')
    status = models.PositiveSmallIntegerField(choices=STATUS_CHOICES, verbose_name=u"状态", default=STOCK)
    guide_price = models.IntegerField(verbose_name=u'指导价')
    sale_price = models.IntegerField(verbose_name=u'售价')
    gearbox = models.CharField(max_length=200, verbose_name=u"变速箱类型", blank=True, null=True)
    color = models.CharField(max_length=20, verbose_name=u"颜色")
    displacement = models.CharField(max_length=20, verbose_name=u"排量")
    emission = models.CharField(max_length=20, verbose_name=u"排放标准")
    address = models.CharField(max_length=50, verbose_name=u"车辆所在地", blank=True, null=True)
    seat_count = models.IntegerField(verbose_name=u"座位数")
    thumbnail = models.ForeignKey(Images, verbose_name=u'缩略图', on_delete=models.PROTECT,
                                  related_name=u'usedvehicle_thumbnail', null=True)
    plate_date = models.DateField(verbose_name=u"上牌日期", blank=True, null=True)
    factory_date = models.DateField(verbose_name=u"出厂日期", blank=True, null=True)
    oil_type = models.CharField(max_length=20, verbose_name=u"燃油类型")
    mileage = models.FloatField(verbose_name=u"车辆里程")
    notes = models.CharField(max_length=200, verbose_name=u"备注", blank=True, null=True)

    class Meta:
        db_table = "usedvehicle"
        verbose_name = u"二手车档案"
        ordering = ('-id',)
        default_permissions = ()


class UsedVehicleImg(models.Model):
    main = models.ForeignKey(UsedVehicle, verbose_name=u'车型', on_delete=models.PROTECT)
    img = models.ForeignKey(Images, verbose_name=u'图片', on_delete=models.PROTECT)

    class Meta:
        db_table = 'usedvehicle_img'
        verbose_name = u'二手车图片'
        default_permissions = ()
