# -*- coding: utf-8 -*-

from django.db import models
from django.utils.translation import ugettext_lazy as _
from django_models_ext import BaseModelMixin
from shortuuidfield import ShortUUIDField


class ScreenAdminInfo(BaseModelMixin):
    MALE = 1
    FEMALE = 0

    SEX_TYPE_TUPLE = (
        (MALE, u'男'),
        (FEMALE, u'女'),
    )

    ACTIVATED = 1
    DISABLED = 2
    DELETED = 3

    USER_STATUS_TUPLE = (
        (ACTIVATED, u'已激活'),
        (DISABLED, u'已禁用'),
        (DELETED, u'已删除'),
    )

    admin_id = ShortUUIDField(_(u'admin_id'), max_length=32, blank=True, null=True, help_text=u'大屏管理员唯一标识', db_index=True, unique=True)

    unionid = models.CharField(_(u'unionid'), max_length=32, blank=True, null=True, help_text=u'微信 Union ID', db_index=True)
    openid = models.CharField(_(u'openid'), max_length=32, blank=True, null=True, help_text=u'微信 Open ID', db_index=True)

    name = models.CharField(_(u'name'), max_length=8, blank=True, null=True, help_text=u'用户姓名')
    sex = models.IntegerField(_(u'sex'), choices=SEX_TYPE_TUPLE, default=MALE, help_text=u'用户性别')
    nickname = models.CharField(_(u'nickname'), max_length=255, blank=True, null=True, help_text=u'用户昵称')
    avatar = models.CharField(_(u'avatar'), max_length=255, blank=True, null=True, help_text=u'用户头像')
    phone = models.CharField(_(u'phone'), max_length=11, blank=True, null=True, help_text=u'用户电话', db_index=True)
    country = models.CharField(_(u'country'), max_length=16, blank=True, null=True, help_text=u'用户国家')
    province = models.CharField(_(u'province'), max_length=16, blank=True, null=True, help_text=u'用户省份')
    city = models.CharField(_(u'city'), max_length=16, blank=True, null=True, help_text=u'用户城市')
    location = models.CharField(_(u'location'), max_length=255, blank=True, null=True, help_text=u'用户地址')

    brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
    brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称')

    user_status = models.IntegerField(_(u'user_status'), choices=USER_STATUS_TUPLE, default=ACTIVATED, help_text=u'管理员状态', db_index=True)

    class Meta:
        verbose_name = _(u'ScreenAdminInfo')
        verbose_name_plural = _(u'ScreenAdminInfo')

        unique_together = (
            ('brand_id', 'unionid', 'openid'),
        )

    def __unicode__(self):
        return unicode(self.pk)

    @property
    def data(self):
        return {
            'nickname': self.nickname,
            'avatar': self.avatar,
        }