from django.db import models
from django.contrib.auth.models import User

class Assignment(models.Model):
    title = models.CharField(max_length=255)
    description = models.TextField()
    due_date = models.DateTimeField()

    def __str__(self):
        return self.title

class Exercise(models.Model):
    assignment = models.ForeignKey(Assignment, related_name='exercises', on_delete=models.CASCADE)
    question = models.TextField()
    answer = models.TextField()

    def __str__(self):
        return self.question

class Submission(models.Model):
    exercise = models.ForeignKey(Exercise, on_delete=models.CASCADE)
    student = models.ForeignKey(User, on_delete=models.CASCADE)
    submitted_answer = models.TextField()
    is_correct = models.BooleanField(default=False)

    def __str__(self):
        return f'{self.student.username} - {self.exercise.question}'

class Hint(models.Model):
    exercise = models.ForeignKey(Exercise, related_name='hints', on_delete=models.CASCADE)
    hint_text = models.TextField()

    def __str__(self):
        return self.hint_text
