from django.core.management.base import BaseCommand


class Command(BaseCommand):
    help = 'Trigger example Celery tasks to verify worker connectivity.'

    def handle(self, *args, **options):
        self.stdout.write('Dispatching example_long_task...')
        try:
            from apps.core.tasks.example_tasks import example_long_task
            result = example_long_task.delay(5)
            self.stdout.write(f'Dispatched example_long_task, task id: {result.id}')
        except Exception as exc:
            self.stderr.write(f'Failed to dispatch example_long_task: {exc}')

        self.stdout.write('Dispatching notifications tasks...')
        try:
            from apps.notifications.tasks import send_email_task, send_sms_task
            r1 = send_email_task.delay('tester', 'test', 'payload')
            r2 = send_sms_task.delay('+123', 'otp')
            self.stdout.write(f'send_email_task id: {r1.id}, send_sms_task id: {r2.id}')
        except Exception as exc:
            self.stderr.write(f'Failed to dispatch notification tasks: {exc}')

        self.stdout.write('Done')
