from app import create_app, db
from app.models.topic import Topic

app = create_app()

with app.app_context():
    # Get the topic
    topic = Topic.query.get(1)
    if topic:
        print(f"Before update:")
        print(f"  Title: {topic.title}")
        print(f"  Category: {topic.category}")
        print(f"  Course ID: {topic.course_id}")
        print(f"  Course Type: {topic.course_type}")
        
        # Update the topic with test data
        topic.title = "Updated Test Title"
        topic.category = "grammar"  # Using a valid category from the form choices
        topic.reading_content = "This is a test reading content for debugging."
        topic.speaking_prompt = "Test speaking prompt."
        topic.writing_prompt = "Test writing prompt."
        
        # Save changes
        db.session.commit()
        db.session.refresh(topic)  # Explicitly refresh from the database
        
        print(f"\nAfter update:")
        print(f"  Title: {topic.title}")
        print(f"  Category: {topic.category}")
        print(f"  Course ID: {topic.course_id}")
        print(f"  Course Type: {topic.course_type}")
        print(f"  Reading Content: {topic.reading_content}")
        
        print("\nChanges made. Please check the student view of this topic now.")
    else:
        print("Topic ID 1 not found")