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

from access.fields import (
    AutoCreatedField,
    AutoLastModifiedField,
)
from access.managers.tenancy import TenancyManager

from core.mixins.centurion import Centurion



class Tenant(
    Centurion,
):

    model_tag = 'tenant'

    objects = TenancyManager()

    class Meta:

        verbose_name = "Tenant"

        verbose_name_plural = "Tenants"

        ordering = [
            'name'
        ]


    id = models.AutoField(
        blank = False,
        help_text = 'ID of this item',
        primary_key = True,
        unique = True,
        verbose_name = 'ID'
    )

    name = models.CharField(
        blank = False,
        help_text = 'Name of this Tenancy',
        max_length = 50,
        unique = True,
        verbose_name = 'Name'
    )

    manager = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        blank = True,
        help_text = 'Manager for this Tenancy',
        null = True,
        on_delete = models.PROTECT,
        verbose_name = 'Manager'
    )

    model_notes = models.TextField(
        blank = True,
        help_text = 'Tid bits of information',
        null = True,
        verbose_name = 'Notes',
    )


    created = AutoCreatedField()

    modified = AutoLastModifiedField()


    def __int__(self):

        return self.id


    def __str__(self):
        return self.name


    def get_organization(self):
        return self

    def get_tenant(self):
        return self


    table_fields: list = [
        'nbsp',
        'name',
        'created',
        'modified',
        'nbsp'
    ]

    page_layout: list = [
        {
            "name": "Details",
            "slug": "details",
            "sections": [
                {
                    "layout": "double",
                    "left": [
                        'name',
                        'manager',
                        'created',
                        'modified',
                    ],
                    "right": [
                        'model_notes',
                    ]
                }
            ]
        },
        {
            "name": "Knowledge Base",
            "slug": "kb_articles",
            "sections": [
                {
                    "layout": "table",
                    "field": "knowledge_base",
                }
            ]
        },
        {
            "name": "Notes",
            "slug": "notes",
            "sections": []
        }
    ]



Organization = Tenant
