from django.contrib.contenttypes.fields import GenericRelation
from django.db import models

class EsPos(models.Model):
    code = models.CharField(max_length=150)
    name = models.CharField(max_length=150)
    desc = models.TextField(null=True)
    department = models.ForeignKey("api.EsDepartment", on_delete=models.SET_NULL, null=True)
    #planned_size = models.IntegerField(null=True)
    #max_credit = models.IntegerField(null=True)
    #academic_term = models.ForeignKey("api.TtAcademicTerm", on_delete=models.CASCADE, null=True)
    status = models.SmallIntegerField()
    extra_data_1 = models.TextField(null=True)
    extra_data_2 = models.TextField(null=True)
    extra_data_3 = models.TextField(null=True)
    extra_data_4 = models.TextField(null=True)
    extra_data_5 = models.TextField(null=True)
    extra_data_6 = models.TextField(null=True)
    extra_data_7 = models.TextField(null=True)
    extra_data_8 = models.TextField(null=True)
    extra_data_9 = models.TextField(null=True)
    extra_data_10 = models.TextField(null=True)
    created_by = models.BigIntegerField(null=True)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_by = models.BigIntegerField(null=True)
    updated_at = models.DateTimeField(auto_now=True)

    #module_group = models.ManyToManyField("api.TtModuleGroup", through="api.TtPosModuleGroup")

    tag = GenericRelation(
        "api.EsTagRelation",
        content_type_field="refer_table",
        object_id_field="refer_id",
    )

    STATUS_TO_CODE = {
        "active": 1,
        "inactive": 2,
    }

    # table need display for delete confirmation
    DELETE_CONFIRMATION_TABLE = [
        #"tt_student_set",
        #"tt_pathway",
    ]

    IMPORT_RULES = {
        "code": ["required", "string", "unique"],
        "name": ["required", "string"],
        "desc": ["nullable", "string"],
        "department_id": ["nullable", "exist"],
        "tag": ["nullable", "string"],
        **{f"extra_data_{i}": ["nullable", "string"] for i in range(1, 11)},
    }

    class Meta:
        db_table = "es_pos"

    def __str__(self):
        return self.name