from flask.globals import current_app

from jjsystem.celery import celery, decide_on_run
from jjsystem.common import exception
from jjsystem.subsystem.user.email import TypeEmail


@decide_on_run
@celery.task(autoretry_for=(exception.NotFound,),
             default_retry_delay=5,
             retry_kwargs={'max_retries': 3})
def send_email(user_id: str) -> None:
    api = current_app.api_handler.api()
    users_manager = api.users()
    return users_manager.notify(id=user_id,
                                type_email=TypeEmail.ACTIVATE_ACCOUNT)
