#coding=utf-8

from django.db import models

from django.conf import settings

from apps.account.models import Branch


class Customer(models.Model):
    branch = models.ForeignKey(Branch, verbose_name=u"门店", related_name='customer_branch', on_delete=models.PROTECT, editable=False)
    user = models.ForeignKey(settings.AUTH_USER_MODEL, editable=False, related_name='customer_user', on_delete=models.PROTECT, verbose_name=u'客户')
    name = models.CharField(max_length=100, verbose_name=u"姓名")
    tel = models.CharField(max_length=50, verbose_name=u'电话')
    gender = models.PositiveSmallIntegerField(choices=settings.GENDER_CHOICES, verbose_name=u'性别', null=True)
    face = models.CharField(max_length=200, verbose_name=u'头像', null=True)

    class Meta:
        db_table = "customer"
        verbose_name = u"客户管理"
        ordering = ['-id']
        index_together = (
            'name',
            'tel',
        )
        default_permissions = ()
        permissions = []


class CustomerWechat(models.Model):
    branch = models.ForeignKey(Branch, verbose_name=u"门店", related_name='customer_wechat_branch', on_delete=models.PROTECT, editable=False)
    customer = models.ForeignKey(Customer, verbose_name=u'用户', related_name='customer_wechat_customer',on_delete=models.PROTECT, editable=False, null=True)
    openid = models.CharField(max_length=512, verbose_name=u"openid")
    session_key = models.CharField(max_length=512, verbose_name=u'session_key',null=True)

    class Meta:
        db_table = 'customer_wechat'
        verbose_name = u'微信客户'
        index_together = (
            'openid',
        )
        default_permissions = ()
