from django.core.management.base import BaseCommand
from apps.business.schemes.models import OpportunityBundle, OpportunityBundleLevel
from apps.business.products.models import Product
from decimal import Decimal

class Command(BaseCommand):
    help = "Seed 18-level scheme for Platinum Opportunity Bundle."

    def handle(self, *args, **options):
        bundle_name = "Platinum"  # Adjust if your bundle name differs
        bundle, _ = OpportunityBundle.objects.get_or_create(name=bundle_name)

        # Level data as per screenshots
        levels = [
            # level_number, required_positions, reward_amount, has_reward, has_service, has_gift, auto_id_enabled, auto_id_count, requires_user_choice, service_product_name, gift_type, gift_product_name, gift_external
            (1, 2, 0, False, False, False, False, 0, False, None, None, None, None),
            (2, 4, 0, False, False, False, False, 0, False, None, None, None, None),
            (3, 8, 750, True, False, False, False, 0, False, None, None, None, None),
            (4, 16, 1000, True, False, False, False, 0, False, None, None, None, None),
            (5, 32, 7500, True, False, False, False, 0, False, None, None, None, None),
            (6, 64, 8500, True, False, False, False, 0, False, None, None, None, None),
            (7, 128, 20000, True, True, False, False, 0, False, "Goa Trip 3D/2N", None, None, None),
            (8, 256, 18000, True, True, True, True, 1, False, "TIRUMALA Darshanam 2D/2N", "inhouse", None, "twertwert"),
            (9, 512, 88000, True, True, False, True, 1, False, "Thailand Vacation 6D/4N", None, None, None),
            (10, 1024, 101400, True, True, False, True, 2, False, "Lakshadweep Trip 4D/3N", None, None, "External gift"),
            (11, 2048, 291000, True, True, True, True, 5, False, None, "inhouse", "Medical Water Device", None),
            (12, 4096, 371000, True, True, True, True, 5, False, "Dubai Vacation 4D/3N", "inhouse", "Smart TV & AC", None),
            (13, 8192, 1441000, True, True, True, True, 10, False, "Indonesia (BALI) Vacation 6D/4N", "inhouse", "Laptop", None),
            (14, 16384, 1623000, True, True, True, True, 15, False, "Andaman Vacation 6D/4N", "inhouse", "Smartphone", None),
            (15, 32768, 5028000, True, True, True, True, 40, False, "Norway 6D/5N", "inhouse", "1 EV BIKES", None),
            (16, 65536, 6115000, True, True, True, True, 75, False, "Malaysia Vacation 6D/6N", "inhouse", "5 LAKH GOLD", None),
            (17, 131072, 11320000, True, True, True, True, 100, False, "Singapore Vacation 6D/6N", "inhouse", "10 LAKH GOLD", None),
            (18, 262144, 20022000, True, True, True, True, 210, False, "Europe Vacation 12D", "inhouse", "2 BHK FLAT", None),
        ]

        OpportunityBundleLevel.objects.filter(opportunity_bundle=bundle).delete()

        for i, (level_number, required_positions, reward_amount, has_reward, has_service, has_gift, auto_id_enabled, auto_id_count, requires_user_choice, service_product_name, gift_type, gift_product_name, gift_external) in enumerate(levels, 1):
            service_product = Product.objects.filter(name=service_product_name).first() if service_product_name else None
            gift_product = Product.objects.filter(name=gift_product_name).first() if gift_product_name else None
            OpportunityBundleLevel.objects.create(
                opportunity_bundle=bundle,
                level_number=level_number,
                display_order=i,
                required_positions=required_positions,
                reward_amount=Decimal(reward_amount),
                has_reward=has_reward,
                has_service=has_service,
                has_gift=has_gift,
                auto_id_enabled=auto_id_enabled,
                auto_id_count=auto_id_count,
                requires_user_choice=requires_user_choice,
                service_product=service_product,
                gift_type=gift_type,
                gift_product=gift_product,
                gift_external=gift_external,
            )
        self.stdout.write(self.style.SUCCESS(f"Seeded 18 levels for bundle: {bundle_name}"))
