from django.conf import settings
from django.db import models

from apps.tenant.models import Tenant


class Area(models.Model):
    name = models.CharField(max_length=100, verbose_name=u'区域名称')
    tenant = models.ForeignKey(Tenant, verbose_name=u'租户', editable=False, on_delete=models.PROTECT)
    notes = models.CharField(max_length=500, verbose_name=u"备注", null=True)
    create_user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=u"创建人", on_delete=models.PROTECT,
                                    editable=False)
    create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    sort = models.PositiveSmallIntegerField(verbose_name=u'排序', help_text=u'越小越靠前', default=0)
    enable = models.BooleanField(verbose_name=u"在用", default=True)
    delete = models.BooleanField(verbose_name=u"删除", default=False, editable=False)

    class Meta:
        db_table = 'area'
        verbose_name = u'区域信息'
        ordering = ['-id',  'sort', ]
        default_permissions = ()
        permissions = [
            ('browse_area', u'查看'),
            ('add_area', u'添加'),
            ('delete_area', u'删除')
        ]


class Department(models.Model):
    name = models.CharField(max_length=100, verbose_name=u'部门名称')
    area = models.ForeignKey(Area, verbose_name=u'所属区域',  on_delete=models.PROTECT)
    notes = models.CharField(max_length=500, verbose_name=u"备注", null=True)
    create_user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=u"创建人", on_delete=models.PROTECT,
                                    editable=False)
    create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    sort = models.PositiveSmallIntegerField(verbose_name=u'排序', help_text=u'越小越靠前', default=0)
    enable = models.BooleanField(verbose_name=u"在用", default=True)
    delete = models.BooleanField(verbose_name=u"删除", default=False, editable=False)

    class Meta:
        db_table = 'area_department'
        verbose_name = u'区域部门'
        ordering = ['-id', 'sort', ]
        default_permissions = ()
        permissions = [
        ]
