from django.core.management.base import BaseCommand

from apps.billing.models import SubscriptionPackage

DEFAULT_PACKAGES = [
    {
        "name": "Starter",
        "price": 2900,
        "billing_cycle": "monthly",
        "member_limit": 100,
        "staff_accounts": 1,
        "description": "Perfect for small gyms just getting started",
        "features": [
            "Up to 100 members",
            "Class scheduling",
            "Basic reporting",
            "Email support",
            "1 staff account",
        ],
        "is_popular": False,
        "is_active": True,
        "sort_order": 1,
    },
    {
        "name": "Professional",
        "price": 7900,
        "billing_cycle": "monthly",
        "member_limit": 500,
        "staff_accounts": 5,
        "description": "For growing gyms that need more power",
        "features": [
            "Up to 500 members",
            "Advanced scheduling",
            "Payment processing",
            "Analytics dashboard",
            "5 staff accounts",
            "Priority support",
        ],
        "is_popular": True,
        "is_active": True,
        "sort_order": 2,
    },
    {
        "name": "Enterprise",
        "price": 19900,
        "billing_cycle": "monthly",
        "member_limit": -1,
        "staff_accounts": -1,
        "description": "For multi-location fitness businesses",
        "features": [
            "Unlimited members",
            "Multi-location support",
            "Custom integrations",
            "Dedicated account manager",
            "Unlimited staff",
            "API access",
            "White-label options",
        ],
        "is_popular": False,
        "is_active": True,
        "sort_order": 3,
    },
]


class Command(BaseCommand):
    help = "Seed default subscription packages"

    def handle(self, *args, **options):
        created = 0
        for pkg_data in DEFAULT_PACKAGES:
            _, was_created = SubscriptionPackage.objects.get_or_create(
                name=pkg_data["name"],
                defaults=pkg_data,
            )
            if was_created:
                created += 1
                self.stdout.write(f"  Created: {pkg_data['name']}")
            else:
                self.stdout.write(f"  Exists: {pkg_data['name']}")

        self.stdout.write(
            self.style.SUCCESS(f"Done. {created} package(s) created.")
        )
