# coding=utf-8

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

class Agent(models.Model):
    name = models.CharField(verbose_name=u'名称', max_length=50)
    tel = models.CharField(verbose_name=u'电话', max_length=20, null=True)
    area = models.CharField(verbose_name=u'区域', max_length=50)
    address = models.CharField(verbose_name=u'地址', max_length=200)
    create_user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=u'添加人',related_name='agent_create_user',
                                    editable=False,on_delete=models.PROTECT)
    create_time = models.DateTimeField(verbose_name=u'添加时间', auto_now_add=True, editable=False)
    notes = models.CharField(verbose_name=u'备注', max_length=200, null=True)

    class Meta:
        db_table = 'agent'
        verbose_name = u'代理商'
        ordering = ['-id']
        default_permissions = ()
        permissions = [
            ('view_agent', u'查看'),
            ('add_agent', u'添加'),
            ('delete_agent', u'删除'),
        ]

class Store(models.Model):

    name = models.CharField(verbose_name=u'名称', max_length=50)
    address = models.CharField(verbose_name=u'地址', max_length=200)
    create_user = models.ForeignKey(settings.AUTH_USER_MODEL,related_name='store_create_user',
                                    editable=False, verbose_name=u'添加人', on_delete=models.PROTECT)
    create_time = models.DateTimeField(verbose_name=u'添加时间', auto_now_add=True, editable=False)
    status = models.PositiveSmallIntegerField(choices=settings.CHECK_STATE_CHOICES, verbose_name=u"状态", default=settings.DEFAULT)
    enable = models.BooleanField(verbose_name=u"是否在用", default=True)
    end_date = models.DateField(verbose_name=u'到期日期', null=True)
    notes = models.CharField(verbose_name=u'备注', max_length=200, null=True)
    agent = models.ForeignKey(Agent, verbose_name=u'代理商', on_delete=models.PROTECT, editable=False)
    check_user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=u'审核人',related_name='store_check_user',
                                   editable=False, on_delete=models.PROTECT)
    check_time = models.DateTimeField(verbose_name=u'审核时间', editable=False, null=True)

    class Meta:
        db_table = 'store'
        verbose_name = u'门店'
        ordering = ['-id']
        default_permissions = ()
        permissions = [
            ('view_store', u'查看'),
            ('add_store', u'添加'),
            ('delete_store', u'删除'),
            ('check_store', u'审核'),
        ]
