from django.core.management.base import BaseCommand
from cashbook.models import Transaction
from cashbook.exporters import export_transactions_qs_to_excel

class Command(BaseCommand):
    help = "Export transactions of a business to Excel"

    def add_arguments(self, parser):
        parser.add_argument("--business_id", type=int, required=True)
        parser.add_argument("--outfile", type=str, required=True)

    def handle(self, *args, **options):
        qs = Transaction.objects.filter(business_id=options["business_id"])
        export_transactions_qs_to_excel(qs, options["outfile"])
        self.stdout.write(self.style.SUCCESS(f"Exported to {options['outfile']}"))
