from django.contrib.auth.models import User
from core.models import Assignment, Exercise, Hint
from datetime import datetime, timedelta

# Create a student user
student, created = User.objects.get_or_create(username='student', defaults={'first_name': 'John', 'last_name': 'Doe'})
if created:
    student.set_password('password')
    student.save()
    print("Student user created.")
else:
    print("Student user already exists.")

# Create an assignment
assignment, created = Assignment.objects.get_or_create(
    title='Math Homework 1',
    defaults={
        'description': 'Complete the following exercises.',
        'due_date': datetime.now() + timedelta(days=7)
    }
)
if created:
    print("Assignment created.")
else:
    print("Assignment already exists.")


# Create exercises
exercise1, created = Exercise.objects.get_or_create(
    assignment=assignment,
    question='What is 2 + 2?',
    defaults={'answer': '4'}
)
if created:
    print("Exercise 1 created.")
else:
    print("Exercise 1 already exists.")


exercise2, created = Exercise.objects.get_or_create(
    assignment=assignment,
    question='What is 5 * 5?',
    defaults={'answer': '25'}
)
if created:
    print("Exercise 2 created.")
else:
    print("Exercise 2 already exists.")


# Create a hint
hint, created = Hint.objects.get_or_create(
    exercise=exercise1,
    defaults={'hint_text': 'The answer is a single digit number.'}
)

if created:
    print("Hint created.")
else:
    print("Hint already exists.")

print("Dummy data creation complete.")
