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

from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django_models_ext import BaseModelMixin

from utils.rdm_utils import randnum


class RegisterStatisticInfo(BaseModelMixin):
    ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True)  # 例：20171208, tc.local_string(format='%Y%m%d')
    num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')

    class Meta:
        verbose_name = _(u'注册用户统计')
        verbose_name_plural = _(u'注册用户统计')

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

    @property
    def data(self):
        return {
            'ymd': self.ymd,
            'num': randnum() if settings.DEBUG_DATA_FLAG else self.num,
        }


class SaleStatisticInfo(BaseModelMixin):
    ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True)  # 例：20171208, tc.local_string(format='%Y%m%d')
    num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')

    class Meta:
        verbose_name = _(u'销量统计')
        verbose_name_plural = _(u'销量统计')

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

    @property
    def data(self):
        return {
            'ymd': self.ymd,
            'num': randnum() if settings.DEBUG_DATA_FLAG else self.num,
        }


class ModelSaleStatisticInfo(BaseModelMixin):
    model_id = models.CharField(_(u'model_id'), max_length=32, help_text=u'型号唯一标识', db_index=True)
    model_name = models.CharField(_(u'model_name'), max_length=255, blank=True, null=True, help_text=u'型号名称')
    ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True)  # 例：20171208, tc.local_string(format='%Y%m%d'), 0 为全部
    num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')

    class Meta:
        verbose_name = _(u'型号销量统计')
        verbose_name_plural = _(u'型号销量统计')

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

    @property
    def data(self):
        return {
            'model_id': self.model_id,
            'model_name': self.model_name,
            'ymd': self.ymd,
            'num': randnum() if settings.DEBUG_DATA_FLAG else self.num,
        }


class DistributorSaleStatisticInfo(BaseModelMixin):
    distributor_id = models.CharField(_(u'distributor_id'), max_length=32, help_text=u'经销商唯一标识', db_index=True)
    distributor_name = models.CharField(_(u'distributor_name'), max_length=255, blank=True, null=True, help_text=u'经销商名称')
    ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True)  # 例：20171208, tc.local_string(format='%Y%m%d'), 0 为全部
    num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')

    class Meta:
        verbose_name = _(u'经销商销量统计')
        verbose_name_plural = _(u'经销商销量统计')

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

    @property
    def data(self):
        return {
            'distributor_id': self.distributor_id,
            'distributor_name': self.distributor_name,
            'ymd': self.ymd,
            'num': randnum() if settings.DEBUG_DATA_FLAG else self.num,
        }


class ProvinceSaleStatisticInfo(BaseModelMixin):
    province_code = models.CharField(_(u'province_code'), max_length=32, help_text=u'省份编码', db_index=True)
    province_name = models.CharField(_(u'province_name'), max_length=32, blank=True, null=True, help_text=u'省份名称')
    ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True)  # 例：20171208, tc.local_string(format='%Y%m%d'), 0 为全部
    num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')

    position = models.IntegerField(_(u'position'), default=1, help_text=u'排序')

    class Meta:
        verbose_name = _(u'省份销量统计')
        verbose_name_plural = _(u'省份销量统计')

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

    @property
    def data(self):
        return {
            'province_code': self.province_code,
            'province_name': self.province_name,
            'ymd': self.ymd,
            'num': randnum() if settings.DEBUG_DATA_FLAG else self.num,
        }
