from celery import shared_task
from celery.utils.log import get_task_logger
from django.conf import settings
from django.core.mail import EmailMessage, send_mail

from templated_email import send_templated_mail

from .models import User

logger = get_task_logger(__name__)


ACCOUNT_CREATED_TEMPLATE = 'accounts/account_created'

@shared_task(name='send_account_created_email')
def send_account_created_email(user):
    send_templated_mail(
        template_name=ACCOUNT_CREATED_TEMPLATE,
        from_email=settings.DEFAULT_FROM_EMAIL,
        recipient_list=[user['email']],
        context=user
    )

    logger.info(f"Account created email sent to {user['email']}")
