from decimal import Decimal
from django.core.management.base import BaseCommand
from apps.business.withdrawals.models import WithdrawalDeductionConfig


class Command(BaseCommand):
    help = 'Seed default withdrawal deduction config with 5 named components at 5% each'

    def handle(self, *args, **options):
        obj, created = WithdrawalDeductionConfig.objects.update_or_create(
            name='Default',
            defaults={
                'tds_percent': Decimal('5.000'),
                'repurchase_percent': Decimal('5.000'),
                'welfare_fund_percent': Decimal('5.000'),
                'technology_charges_percent': Decimal('5.000'),
                'operations_charges_percent': Decimal('5.000'),
                'is_active': True,
            },
        )
        verb = 'Created' if created else 'Updated'
        self.stdout.write(self.style.SUCCESS(
            f'{verb} Default deduction config (id={obj.id}): '
            f'TDS=5%, Repurchase=5%, Welfare=5%, Technology=5%, Operations=5% (total=25%)'
        ))
