"""
Base celery tasks
"""

from celery import shared_task
from django.utils.translation import gettext as _

from core.services import sms_service
from core.utils import console


@shared_task
def SendConfirm(phone, code):
    try:
        service: sms_service.SendService = sms_service.SendService()
        message = _("Sizning Tasdiqlash ko'dingiz: %(code)s") % {"code": code}
        res = service.send_sms(phone, message)
        
        if res.get("status") == "success" or res.get("status") == "waiting":
            console.Console().success(f"SMS Sent Successfully: {phone}-{code} | Response: {res}")
        else:
            console.Console().error(f"SMS Failed: {phone}-{code} | Error: {res}")
            
    except Exception as e:
        console.Console().error(
            "Exception in SendConfirm task: {phone}-{code}\n\n{error}".format(
                phone=phone, code=code, error=str(e)
            )
        )
