from celery import shared_task
from .services import send_notification as send_notification_service
from .delivery import process_due_campaigns


@shared_task
def send_email_task(user_id: str, subject: str, body: str):
    # placeholder: integrate with email provider
    # in production, load user and send email
    return {'ok': True, 'user_id': user_id}


@shared_task
def send_sms_task(recipient: str, message: str):
    # placeholder: integrate with SMS provider
    return {'ok': True, 'recipient': recipient}


@shared_task
def process_notification_task(notification_id: str):
    # process / send a Notification record asynchronously
    try:
        send_notification_service(channel='email', recipient='', template_code=None, context={'notification_id': notification_id})
    except Exception:
        pass
    return {'ok': True, 'notification_id': notification_id}


@shared_task
def process_scheduled_notification_campaigns_task():
    return process_due_campaigns()
