from django.db import models


# Create your models here.
# 用户表
class UserModel(models.Model):
    id = models.AutoField(primary_key=True)
    username = models.CharField(max_length=64, unique=True, default='', verbose_name='用户名')
    password = models.CharField(max_length=128, default='', verbose_name='密码')
    role_id = models.CharField(max_length=64, default='', verbose_name='角色')
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    updTime = models.IntegerField(verbose_name='更新时间', default=0)
    role_type = models.IntegerField(verbose_name='角色类型', default=0)

    class Meta:
        ordering = ('-addTime',)
        verbose_name = '用户表'
        db_table = 'lang_user'

    def __str__(self):
        return self.username


# 语种
class LangAreaModel(models.Model):
    id = models.AutoField(primary_key=True)
    lang = models.CharField(max_length=32, default='', verbose_name='语言')
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    updTime = models.IntegerField(verbose_name='更新时间', default=0)

    class Meta:
        ordering = ('-addTime',)
        verbose_name = '语种'
        db_table = 'lang_area'


# 用户关联语种配置
class LangSetModel(models.Model):
    id = models.AutoField(primary_key=True)
    user = models.ForeignKey(UserModel, verbose_name='用户表id', to_field='id', on_delete=models.CASCADE)
    lang = models.ForeignKey(LangAreaModel, verbose_name='关联语种id', to_field='id', on_delete=models.CASCADE)
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    updTime = models.IntegerField(verbose_name='更新时间', default=0)

    class Meta:
        ordering = ('-addTime',)
        verbose_name = '用户关联语种配置'
        db_table = 'lang_set'

class LangProjectModel(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32, null=False, verbose_name='项目名')
    add_time = models.IntegerField(default=0, verbose_name='添加时间')
    update_time = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        verbose_name = '语言项目'
        verbose_name_plural = verbose_name
        db_table = 'lang_project'

class LangKeyModel(models.Model):
    id = models.AutoField(primary_key=True)
    word_key = models.CharField(default='', max_length=64, verbose_name='词汇键')
    project = models.ForeignKey(LangProjectModel, null=True, to_field='id', on_delete=models.CASCADE, verbose_name='关联项目表')
    addTime = models.IntegerField(default=0, verbose_name='添加时间')
    updTime = models.IntegerField(default=0, verbose_name='更新时间')
    '''
    # 00000001：移动端；00000010：pc端（avss）；00000100：Zosi Link
    '''
    type = models.SmallIntegerField(default=1, verbose_name='词汇键类型')

    class Meta:
        unique_together = ('word_key', 'project')
        ordering = ('-addTime',)
        verbose_name = '词汇k表'
        db_table = 'lang_key'


class LangValModel(models.Model):
    id = models.AutoField(primary_key=True)
    lk = models.ForeignKey(LangKeyModel, null=True, verbose_name='v关联词汇k', to_field='id', on_delete=models.CASCADE)
    la = models.ForeignKey(LangAreaModel, null=True, verbose_name='词汇k关联语种', to_field='id', on_delete=models.CASCADE)
    word_val = models.CharField(default='', max_length=64, verbose_name='词汇v')
    addTime = models.IntegerField(default=0, verbose_name='添加时间')
    updTime = models.IntegerField(default=0, verbose_name='更新时间')
    status = models.IntegerField(default=0, verbose_name='编辑状态') #-------0：重置后；1：新增；2：编辑后

    class Meta:
        ordering = ('-addTime',)
        verbose_name = '词汇v表'
        db_table = 'lang_val'


#
class AsImgModel(models.Model):
    id = models.AutoField(primary_key=True)  # 主键
    asin = models.CharField(default='', max_length=32, verbose_name='产品编码', db_index=True)  # 产品asin吗，唯一
    url = models.CharField(default='', max_length=128, verbose_name='产品图片url')
    md5 = models.CharField(default='', max_length=128, verbose_name='图片md5')
    addTime = models.IntegerField(default=0, verbose_name="添加时间")
    updTime = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        ordering = ('-addTime',)
        verbose_name = '亚马逊图片表'
        db_table = 'as_img'


class SysSetModel(models.Model):
    id = models.AutoField(primary_key=True)
    key = models.CharField(default='', max_length=64, verbose_name='键名')  # 亚马逊产品图片检测邮箱
    val = models.CharField(default='', max_length=64, verbose_name='键值')  # 亚马逊产品图片检测邮箱
    addTime = models.IntegerField(default=0, verbose_name='添加时间')
    updTime = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        ordering = ('-addTime',)
        verbose_name = '系统配置表'
        db_table = 'sys_set'


# 手机注册表 抽奖
class phoneNumModel(models.Model):
    id = models.AutoField(primary_key=True)
    phone = models.CharField(default='', verbose_name='手机', max_length=11)
    status = models.SmallIntegerField(default=0, verbose_name='中奖状态')  # 1为c611,2为c612
    addr = models.TextField(blank=True, default='', verbose_name=u'更新内容')
    addTime = models.IntegerField(default=0, verbose_name='添加时间')
    updTime = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        ordering = ('-addTime',)
        verbose_name = '手机注册表'
        db_table = 'phoneNum'

# sku套装名称表
class skuSuitModel(models.Model):
    id = models.AutoField(primary_key=True)
    suitName = models.CharField(default='', verbose_name='套装名称', max_length=64)
    addTime = models.IntegerField(default=0, verbose_name='添加时间')
    updTime = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        ordering = ('-id',)
        verbose_name = 'sku套装名称表'
        db_table = 'sku_suit_name'

# sku规则名称表
class skuRuleModel(models.Model):
    id = models.AutoField(primary_key=True)
    rs = models.ForeignKey(skuSuitModel, verbose_name='关联套装名称表', to_field='id', on_delete=models.CASCADE)
    ruleName = models.CharField(default='', verbose_name='规则名称', max_length=64)
    addTime = models.IntegerField(default=0, verbose_name='添加时间')
    updTime = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        ordering = ('-id',)
        verbose_name = 'sku规则名称表'
        db_table = 'sku_rule_name'

#sku 条件表
class skuConditionModel(models.Model):
    id = models.AutoField(primary_key=True)
    cr = models.ForeignKey(skuRuleModel , verbose_name='关联规则名称表', to_field='id', on_delete=models.CASCADE)
    numName = models.CharField(default='', verbose_name='字母表示', max_length=64)
    conditionName = models.CharField(default='', verbose_name='条件名称', max_length=64)
    addTime = models.IntegerField(default=0, verbose_name='添加时间')
    updTime = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        ordering = ('-id',)
        verbose_name = 'sku条件表'
        db_table = 'sku_condition_name'


# 用户关联可编辑语种配置
class LangPermModel(models.Model):
    id = models.AutoField(primary_key=True)
    user = models.ForeignKey(UserModel, verbose_name='用户表id', to_field='id', on_delete=models.CASCADE)
    lang = models.ForeignKey(LangAreaModel, verbose_name='关联语种id', to_field='id', on_delete=models.CASCADE)
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    updTime = models.IntegerField(verbose_name='更新时间', default=0)

    class Meta:
        ordering = ('-addTime',)
        verbose_name = '用户关联语种配置'
        db_table = 'lang_perm'


class LangClassModel(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=64, unique=True, verbose_name='avss中的context的name')

    class Meta:
        verbose_name = 'avss的模块表'
        verbose_name_plural = verbose_name
        db_table = 'lang_class'


class LangKeyClassModel(models.Model):
    id = models.AutoField(primary_key=True)
    lk = models.ForeignKey(LangKeyModel, null=True, to_field='id', on_delete=models.CASCADE, verbose_name='关联词汇键表')
    clazz = models.ForeignKey(LangClassModel, to_field='id', on_delete=models.CASCADE, verbose_name='关联avss模块表')

    class Meta:
        verbose_name = '词汇键与avss模块映射表'
        verbose_name_plural = verbose_name
        db_table = 'lang_key_class'


class LangLocationModel(models.Model):
    id = models.AutoField(primary_key=True)
    lk = models.ForeignKey(LangKeyModel, null=True, to_field='id', on_delete=models.CASCADE, verbose_name='关联词汇键表')
    filename = models.TextField(default='', null=False, verbose_name='类的路径')
    line = models.IntegerField(default=0, verbose_name='所在的类的行')

    class Meta:
        verbose_name = 'avss的词汇的位置'
        verbose_name_plural = verbose_name
        db_table = 'lang_location'



# 用户关联可编辑项目配置
class ProjectPermModel(models.Model):
    id = models.AutoField(primary_key=True)
    user = models.ForeignKey(UserModel, to_field='id', on_delete=models.CASCADE, verbose_name='关联用户表')
    project = models.ForeignKey(LangProjectModel, to_field='id', on_delete=models.CASCADE, verbose_name='关联项目表')

    class Meta:
        verbose_name = '用户关联项目表'
        verbose_name_plural = verbose_name
        db_table = 'project_perm'

class  SearchToolBlock(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(default='', unique=True, max_length=200, verbose_name='块名称')
    type = models.CharField(default='', max_length=20, verbose_name='协议类型')
    addTime = models.IntegerField(verbose_name='添加时间', default=0)
    updTime = models.IntegerField(verbose_name='更新时间', default=0)

    class Meta:
        verbose_name = '协议块存储'
        verbose_name_plural = verbose_name
        db_table = 'search_tool_block'


# key关联可编辑协议内容
class SearchToolKeyModel(models.Model):
    id = models.AutoField(primary_key=True)
    lk = models.ForeignKey(LangKeyModel, to_field='id', on_delete=models.CASCADE, verbose_name='关联词汇键表')
    bk = models.ForeignKey(SearchToolBlock, to_field='id', on_delete=models.DO_NOTHING, verbose_name='协议块存储')

    class Meta:
        verbose_name = 'key关联协议表'
        verbose_name_plural = verbose_name
        db_table = 'search_tool_block_key'

'''  ------------------------------智能客服 start-------------------------------------------'''
class EmailLangConfig(models.Model):
    emaillangid = models.AutoField(primary_key=True, verbose_name=u'自增ID')
    lang = models.CharField(max_length=32, verbose_name=u'语言')
    langcode = models.CharField(max_length=32, verbose_name=u'语言编码')
    langdescribe = models.CharField(max_length=64, verbose_name=u'语言描述')

    class Meta:
        db_table = 'langconfig'
        verbose_name = u'语言配置'
        verbose_name_plural = verbose_name


class EmailSortModel(models.Model):
    emailsortid = models.AutoField(primary_key=True, verbose_name=u'自增ID')
    sort = models.CharField(max_length=200, default='', verbose_name='负责分类')
    clientquestion = models.CharField(max_length=200, default='', verbose_name='客户问题内容')
    sortcode = models.CharField(max_length=200, default='', verbose_name='分类编号')
    parentsortid = models.CharField(max_length=200, null=True, verbose_name='父节点分类')
    isautoreply = models.SmallIntegerField(default=0, verbose_name='是否自动回复')  # 0：不自动回复 1：自动回复
    autoreplymodel = models.TextField(blank=True, null=True, verbose_name=u'回复模板')
    # iszhuanfa = models.SmallIntegerField(default=0, verbose_name='是否转发其同事处理')  # 0：不 1：是
    # zhuanfauser = models.ForeignKey(UserInfo, to_field='userid', on_delete=models.CASCADE) # 转发用户ID

    class Meta:
        db_table = 'emailsort'
        verbose_name = u'邮箱分类配置表'
        verbose_name_plural = verbose_name

class EmailProjectConfigModel(models.Model):
    emailprojectid = models.AutoField(primary_key=True)
    projecname = models.CharField(max_length=200, default='', verbose_name='项目名')
    projeccode = models.CharField(max_length=200, default='', verbose_name='项目编号')

    class Meta:
        db_table = 'emailprojectconfig'
        verbose_name = '邮箱项目配置表'
        verbose_name_plural = verbose_name

class EmailConfigModel(models.Model):
    emailid = models.AutoField(primary_key=True)
    fromaddr = models.CharField(max_length=200, default='', verbose_name='邮箱账号')
    password = models.CharField(max_length=64, default='', verbose_name='客户端授权码')
    emailservername = models.CharField(max_length=64, default='', verbose_name='邮箱服务器名称')
    emailserver = models.CharField(max_length=64, default='', verbose_name='邮箱服务器地址')
    emailserverport = models.IntegerField(default=0, verbose_name='邮箱服务器端口')
    emailserverportagreement = models.CharField(max_length=64, default='', verbose_name='邮箱服务器协议')
    emaillangconfig = models.ManyToManyField(to='EmailLangConfig', blank=True, verbose_name=u'邮箱负责语言', db_table='emaillang')
    emailproject = models.ForeignKey(EmailProjectConfigModel, to_field='emailprojectid', on_delete=models.CASCADE, verbose_name='邮箱项目配置表')
    emailsort = models.ForeignKey(EmailSortModel, to_field='emailsortid', on_delete=models.CASCADE, verbose_name='邮箱分类配置表')
    emailtag = models.SmallIntegerField(default=0, verbose_name='邮箱标签')  # 0：个人 1：总部 2：其他
    class Meta:
        db_table = 'emailconfig'
        verbose_name = '邮箱配置表'
        verbose_name_plural = verbose_name

'''  ------------------------------智能客服 end-------------------------------------------'''
