import os
from app import app, db
from models import (
    Contest, ContestMembership, ContestApplication, ContestRegistration,
    Exam, Submission, Draft, ExamBookmark,
    Post, Reply, Poll, Reaction, Bookmark, Report,
    QuestionBankItem, Notification, SystemNotification,
    TeacherApplication, InviteCode, ChatRoom, ChatRoomMember, Message
)

def clean_test_data():
    with app.app_context():
        # 删除所有跟杯赛相关的记录
        ContestMembership.query.delete()
        ContestApplication.query.delete()
        ContestRegistration.query.delete()
        QuestionBankItem.query.delete()
        TeacherApplication.query.delete()
        InviteCode.query.delete()
        Contest.query.delete()
        
        # 删除所有跟考试相关的记录
        Submission.query.delete()
        Draft.query.delete()
        ExamBookmark.query.delete()
        Exam.query.delete()

        # 删除所有跟帖子相关的记录
        Reply.query.delete()
        Poll.query.delete()
        Reaction.query.delete()
        Bookmark.query.delete()
        Report.query.delete()
        Post.query.delete()
        
        # 删除聊天系统相关的记录（因为有自动为杯赛建群的功能，顺便清一下比较干净）
        Message.query.delete()
        ChatRoomMember.query.delete()
        ChatRoom.query.delete()
        
        # 也可以清理系统通知、普通通知
        Notification.query.delete()
        SystemNotification.query.delete()

        db.session.commit()
        print("所有测试的杯赛、考试、帖子及相关数据已成功删除！")

if __name__ == '__main__':
    clean_test_data()
