from django.core.management.base import BaseCommand
from finance.mpesa import MpesaClient


class Command(BaseCommand):
    help = 'Register M-Pesa C2B validation and confirmation URLs with Safaricom'

    def handle(self, *args, **options):
        self.stdout.write('Registering C2B URLs with Safaricom...')
        mpesa = MpesaClient()
        response = mpesa.register_c2b_urls()
        if response.get('ResponseDescription'):
            self.stdout.write(
                self.style.SUCCESS(
                    f"Success: {response.get('ResponseDescription')}"
                )
            )
        else:
            self.stdout.write(
                self.style.ERROR(f"Failed: {response}")
            )