# coding=utf-8

from django.db import models
from django.conf import settings

from apps.foundation.models import Option
from apps.vehicle.models import Model
from apps.customer.models import Customer
from apps.store.models import Shop
from apps.images.models import Images


class VehicleDriveReserve(models.Model):
    WAIT_DRIVE = 1
    FINISHED = 2
    REVOKE = 3
    STATUS_CHOICES = (
        (WAIT_DRIVE, u'待试驾'),
        (FINISHED, u'已试驾'),
        (REVOKE, u'已取消'),
    )
    model = models.ForeignKey(Model, verbose_name=u'车型', on_delete=models.PROTECT)
    shop = models.ForeignKey(Shop, verbose_name=u'门店', on_delete=models.PROTECT)
    create_time = models.DateTimeField(verbose_name=u"添加时间", auto_now_add=True, editable=False)
    status = models.PositiveSmallIntegerField(choices=STATUS_CHOICES, verbose_name=u'状态', default=WAIT_DRIVE)
    customer = models.ForeignKey(Customer, verbose_name=u'客户', on_delete=models.PROTECT, editable=False)
    name = models.CharField(max_length=100, verbose_name=u'名称', null=True)
    tel = models.CharField(max_length=20, verbose_name=u'电话', null=True)
    date = models.DateField(verbose_name=u'预约日期', null=True)
    notes = models.CharField(max_length=500, verbose_name=u'备注', null=True)
    delete = models.BooleanField(verbose_name=u'删除', default=False, editable=False)

    class Meta:
        db_table = 'vehicle_drive_reserve'
        verbose_name = u'试驾预约'
        ordering = ("-id",)
        default_permissions = ()


class VehicleInquiry(models.Model):
    WAIT_VISIT = 1
    VISITED = 2
    STATUS_CHOICES = (
        (WAIT_VISIT, u'待回访'),
        (VISITED, u'已回访'),
    )
    model = models.ForeignKey(Model, verbose_name=u'车型', on_delete=models.PROTECT)
    shop = models.ForeignKey(Shop, verbose_name=u'门店', on_delete=models.PROTECT)
    create_time = models.DateTimeField(verbose_name=u"添加时间", auto_now_add=True, editable=False)
    status = models.PositiveSmallIntegerField(choices=STATUS_CHOICES, verbose_name=u'状态', default=WAIT_VISIT)
    customer = models.ForeignKey(Customer, verbose_name=u'客户', on_delete=models.PROTECT, editable=False)
    name = models.CharField(max_length=100, verbose_name=u'名称', null=True)
    tel = models.CharField(max_length=20, verbose_name=u'电话', null=True)
    area = models.CharField(max_length=100, verbose_name=u'城市', null=True)
    displace = models.BooleanField(verbose_name=u'置换', default=False, editable=False)
    notes = models.CharField(max_length=500, verbose_name=u'备注', null=True)
    delete = models.BooleanField(verbose_name=u'删除', default=False, editable=False)

    class Meta:
        db_table = 'vehicle_inquiry'
        verbose_name = u'新车询价'
        ordering = ("-id",)
        default_permissions = ()


class UsedVehicleInquiry(models.Model):
    WAIT_VISIT = 1
    VISITED = 2
    STATUS_CHOICES = (
        (WAIT_VISIT, u'待回访'),
        (VISITED, u'已回访'),
    )
    brand = models.ForeignKey(Option, verbose_name=u'品牌', on_delete=models.PROTECT)
    create_time = models.DateTimeField(verbose_name=u"添加时间", auto_now_add=True, editable=False)
    status = models.PositiveSmallIntegerField(choices=STATUS_CHOICES, verbose_name=u'状态', default=WAIT_VISIT)
    customer = models.ForeignKey(Customer, verbose_name=u'客户', on_delete=models.PROTECT, editable=False)
    name = models.CharField(max_length=100, verbose_name=u'名称', null=True)
    gender = models.PositiveSmallIntegerField(choices=settings.GENDER_CHOICES, verbose_name=u'性别', null=True)
    years = models.CharField(max_length=100, verbose_name=u'车龄', null=True)
    area = models.CharField(max_length=100, verbose_name=u'城市', null=True)
    mileage = models.FloatField(verbose_name=u"车辆里程", null=True)
    notes = models.CharField(max_length=500, verbose_name=u'备注', null=True)
    delete = models.BooleanField(verbose_name=u'删除', default=False, editable=False)

    class Meta:
        db_table = 'usedvehicle_inquiry'
        verbose_name = u'二手车询价'
        ordering = ("-id",)
        default_permissions = ()


class UsedVehicleEstimate(models.Model):
    WAIT_VISIT = 1
    VISITED = 2
    STATUS_CHOICES = (
        (WAIT_VISIT, u'待回访'),
        (VISITED, u'已回访'),
    )
    brand = models.ForeignKey(Option, verbose_name=u'品牌', on_delete=models.PROTECT)
    shop = models.ForeignKey(Shop, verbose_name=u'门店', on_delete=models.PROTECT)
    create_time = models.DateTimeField(verbose_name=u"添加时间", auto_now_add=True, editable=False)
    status = models.PositiveSmallIntegerField(choices=STATUS_CHOICES, verbose_name=u'状态', default=WAIT_VISIT)
    customer = models.ForeignKey(Customer, verbose_name=u'客户', on_delete=models.PROTECT, editable=False)
    tel = models.CharField(max_length=20, verbose_name=u'电话', null=True)
    model = models.CharField(max_length=100, verbose_name=u'车型', null=True)
    plate_date = models.DateField(verbose_name=u"上牌日期", blank=True, null=True)
    area = models.CharField(max_length=100, verbose_name=u'城市', null=True)
    mileage = models.FloatField(verbose_name=u"车辆里程", null=True)
    notes = models.CharField(max_length=500, verbose_name=u'备注', null=True)
    delete = models.BooleanField(verbose_name=u'删除', default=False, editable=False)

    class Meta:
        db_table = 'usedvehicle_estimate'
        verbose_name = u'二手车预估'
        ordering = ("-id",)
        default_permissions = ()


class InsurConsultation(models.Model):
    WAIT_VISIT = 1
    VISITED = 2
    STATUS_CHOICES = (
        (WAIT_VISIT, u'待回访'),
        (VISITED, u'已回访'),
    )
    shop = models.ForeignKey(Shop, verbose_name=u'门店', on_delete=models.PROTECT)
    create_time = models.DateTimeField(verbose_name=u"添加时间", auto_now_add=True, editable=False)
    status = models.PositiveSmallIntegerField(choices=STATUS_CHOICES, verbose_name=u'状态', default=WAIT_VISIT)
    customer = models.ForeignKey(Customer, verbose_name=u'客户', on_delete=models.PROTECT, editable=False)
    name = models.CharField(max_length=100, verbose_name=u'名称', null=True)
    tel = models.CharField(max_length=20, verbose_name=u'电话', null=True)
    content = models.CharField(max_length=1000, verbose_name=u'内容', null=True)
    delete = models.BooleanField(verbose_name=u'删除', default=False, editable=False)

    class Meta:
        db_table = 'insur_consultation'
        verbose_name = u'续保咨询'
        ordering = ("-id",)
        default_permissions = ()