from celery import shared_task
from .utils import send_email
from .models import PollParticipant


@shared_task(rate_limit='3/m')
def send_asynchrone_email(subject: str, receivers: list, template: str, context: dict):
    poll_participant = PollParticipant.objects.get(participant__email=receivers[0], poll__id=context['poll_id'])
    # send_email(subject, receivers, template, context)    
    poll_participant.is_emailed = True
    poll_participant.save()
    
    return f"Email sent to {poll_participant.participant}"