import json

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

class TtActivity(models.Model):
    code = models.CharField(max_length=150)
    name = models.CharField(max_length=255)
    desc = models.TextField(null=True)
    activity_template = models.ForeignKey("api.TtActivityTemplate", on_delete=models.CASCADE, null=True)
    activity_type = models.ForeignKey("api.TtActivityType", on_delete=models.SET_NULL, null=True)
    department = models.ForeignKey("api.TtDepartment", on_delete=models.SET_NULL, null=True)
    academic_term = models.ForeignKey("api.TtAcademicTerm", on_delete=models.CASCADE, null=True)
    module = models.ForeignKey("api.TtModule", on_delete=models.CASCADE, null=True)
    duration = models.IntegerField(null=True,db_comment="in minute")
    slot_required = models.IntegerField(null=True)
    planned_size = models.IntegerField(null=True)
    scheduled_start_time = models.TimeField(null=True)
    scheduled_day = models.SmallIntegerField(null=True,db_comment="0 - Monday, 6 - Sunday")
    scheduled_start_slot = models.IntegerField(null=True, db_comment="0-335(depends on based setting)")
    week_pattern = models.ForeignKey("api.TtWeekPattern",on_delete=models.SET_NULL,null=True,blank=True,db_comment="NULL means custom")
    is_jta = models.IntegerField(null=True,default=0)
    jta_parent = models.ForeignKey('self',on_delete=models.SET_NULL,null=True,blank=True,related_name="jta_children",db_comment="actually is the 2 parent have this value of the new child id")
    is_variant = models.IntegerField(null=True,default=0)
    variant_parent = models.ForeignKey('self',on_delete=models.SET_NULL,null=True,blank=True,related_name="variant_children")
    scheduled = models.IntegerField(null=True,default=0)
    is_booking = models.IntegerField(null=True,default=0)
    status = models.SmallIntegerField()
    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)

    # wont add column, just want create relation between staff and tt_tag_relation table
    week = models.ManyToManyField("api.TtWeek",through="api.TtActivityWeek")
    staff = models.ManyToManyField("api.TtStaff",through="api.TtActivityStaff")
    location = models.ManyToManyField("api.TtLocation",through="api.TtActivityLocation")
    student_set = models.ManyToManyField("api.TtStudentSet",through="api.TtStudentSetActivity")

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

    class Meta:
        db_table = "tt_activity"

    def __str__(self):
        return self.name