from django.core.management.base import BaseCommand

from api.models import TtStaff, TtLocation, TtStudentSet, TtActivityTemplate, TtActivity
from api.utils import convert_to_redis_week, bulk_sync_to_redis
from backend.redis_client import redis_client

class Command(BaseCommand):
    def handle(self, *args, **options):
        redis_data={
            "update":{},
        }
        redis_student_set_table = "student_set"

        student_sets = TtStudentSet.objects.all().prefetch_related("constraint_profile")
        for val in student_sets:
            redis_data["update"].setdefault(redis_student_set_table, []).append({
                "id": val.id,
                "constraint_profile": [relation.id for relation in val.constraint_profile.all()],
            })

        bulk_sync_to_redis(redis_client, redis_data)




