from django.db import models  
##
# @brief This class is used to create the Person table 
##
class Person(models.Model): 
	"""This class is used to create the Person table in the database. In which we will be storing the information of the studebnts and Professors"""
	pid = models.CharField(max_length=20)
	fname = models.CharField(max_length=20) 
	lname = models.CharField(max_length=20)
	password = models.CharField(max_length=20)
	is_prof = models.BooleanField(default=False) 

	def __str__(self):
		return "%s %s" % (self.fname, self.lname)

	class Meta:
		db_table = "person" 
##
# @brief This class is used to create the Subject table 
##
class Subject(models.Model): 
	"""This class is used to create the Subject table in the database in which we will be storing the subject created by the Professors""" 
	sub_code = models.CharField(max_length=5)
	sub_name = models.CharField(max_length=100)
	sub_detail = models.CharField(max_length=500)
	prof = models.ForeignKey(Person, on_delete=models.CASCADE) 

	def __str__(self):
		return self.sub_code

	class Meta:
		db_table = "subject"
##
# @brief This class is used to create the Subject_Student table 
##
class Subject_Student(models.Model):
	"""This class is used to create the Subject_Student table in the database. In which we will be storing the subject taken by the students that bon ACCEPTED nad PENDING subjects"""
	subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
	student = models.ForeignKey(Person, on_delete=models.CASCADE)
	is_accepted = models.BooleanField(default=False)

	class Meta:  
		db_table = "subject_student"
	def __str__(self):
		return "%s %s" % (self.student.fname, self.subject.sub_name)
##
# @brief This class is used to create the Topic table 
##
class Topic(models.Model): 
	"""This class is used to create the Topic Table in the database.In which we will bw storing the subject wise disscussion topic p""" 
	title = models.CharField(max_length=100) 
	subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
	is_prof_included = models.BooleanField(default=True)

	def __str__(self):
		return "%s %s %d" % (self.title, self.subject.sub_name, self.id)

	class Meta:  
		db_table = "topic"
##
# @brief This class is used to create the Thread table 
##
class Thread(models.Model):  
	"""This class is used to create the Thread table in database. In which we will be storing the Topic wise Threads for particular  Subject"""
	title = models.CharField(max_length=50)
	msg = models.CharField(max_length=500) 
	topic = models.ForeignKey(Topic, on_delete=models.CASCADE) 
	person = models.ForeignKey(Person, on_delete=models.CASCADE)
	likes = models.IntegerField(default=0)
	dislikes = models.IntegerField(default=0)
	time = models.DateTimeField(auto_now_add=True, blank=True)

	def __str__(self):
		return "%s  %s" % (self.title, self.topic.title)

	class Meta:  
		db_table = "thread"
##
# @brief This class is used to create the Like table 
##
class Like(models.Model):
	"""This class is used to create the Like table in database. In which we will be storing the like count for each thread"""
	thread = models.ForeignKey(Thread, on_delete=models.CASCADE) 
	person = models.ForeignKey(Person, on_delete=models.CASCADE)
	is_liked = models.BooleanField(default=True) 

	def __str__(self):
		return str(self.id)

	class Meta:  
		db_table = "like"