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

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

from course.basemodels import CreateUpdateMixin


class UserInfo(CreateUpdateMixin):
    UNVERIFIED = 0
    ACTIVATED = 1
    DISABLED = 2
    DELETED = 3

    USER_STATUS = (
        (UNVERIFIED, u'未验证'),
        (ACTIVATED, u'已激活'),
        (DISABLED, u'已禁用'),
        (DELETED, u'已删除'),
    )

    MALE = 1
    FEMALE = 0

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

    user_id = ShortUUIDField(_(u'user_id'), max_length=255, help_text=u'用户唯一标识', db_index=True, unique=True)

    # 微信授权用户
    unionid = models.CharField(_(u'unionid'), max_length=255, blank=True, null=True, help_text=u'微信 Unionid', db_index=True, unique=True)
    openid = models.CharField(_(u'openid'), max_length=255, blank=True, null=True, help_text=u'微信 Openid', db_index=True, unique=True)
    # 用户基本信息
    name = models.CharField(_(u'name'), max_length=255, blank=True, null=True, help_text=u'用户姓名')
    sex = models.IntegerField(_(u'sex'), choices=SEX_TYPE, 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=255, blank=True, null=True, help_text=u'用户电话', db_index=True, unique=True)
    country = models.CharField(_(u'country'), max_length=255, blank=True, null=True, help_text=u'用户国家')
    province = models.CharField(_(u'province'), max_length=255, blank=True, null=True, help_text=u'用户省份')
    city = models.CharField(_(u'city'), max_length=255, blank=True, null=True, help_text=u'用户城市')
    location = models.CharField(_(u'location'), max_length=255, blank=True, null=True, help_text=u'用户地址')

    user_status = models.IntegerField(_(u'user_status'), choices=USER_STATUS, default=UNVERIFIED)

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

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

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