from celery import shared_task
from django.core import serializers
from django.http import JsonResponse
from .models import Transcripts


@shared_task
def check_transcripts(id_transcript):
    """
    A Celery task that checks if three of the `Transcripts` model's attributes are not empty, and returns a JSON response 
    with serialized transcripts.
    
    Args:
        id_transcript (str): The ID of the transcript object to process.
        
    Returns:
        A JSON response with serialized transcripts if three of the `Transcripts` model's attributes are not empty. 
        Otherwise, a JSON response with a message that says "Please wait, your file is processing now."
    """
    
    # Retrieve the transcript object by ID
    transcript = Transcripts.objects.get(id_transcript=id_transcript)
    
    # Check if three of the transcript's attributes are not null or empty
    if transcript.path_srt_fr and transcript.path_srt_es and transcript.path_srt_en:
        # Serialize the transcripts and return them in a JSON response
        data = serializers.serialize('json', [transcript])
        return JsonResponse({'transcripts': data})
    else:
        # Return a JSON response with a message indicating that the file is still processing
        return JsonResponse({'message': 'Please wait, your file is processing now.'})