from decimal import Decimal
from django.core.management.base import BaseCommand
from configuration.models import SiteConfiguration, VATRate


class Command(BaseCommand):
    help = "Ensure SiteConfiguration singleton and default VAT rates exist."

    def handle(self, *args, **kwargs):
        config, created = SiteConfiguration.objects.get_or_create(pk=1)
        if created:
            self.stdout.write(self.style.SUCCESS("Created default SiteConfiguration."))
        else:
            self.stdout.write("SiteConfiguration already exists.")

        if not VATRate.objects.filter(is_active=True).exists():
            VATRate.objects.create(name="Standard", rate=Decimal('21.0000'), is_default=True, is_active=True)
            self.stdout.write(self.style.SUCCESS("Created default VAT rate (21%)."))
        else:
            self.stdout.write("VAT rates already exist.")
