
# # management/commands/load_sample_data.py
# """
# Django management command to load sample data
# Run: python manage.py load_sample_data
# """
# from django.core.management.base import BaseCommand
# from core.models import Product, CategoryAttributeRule
# from data.sample_data import SAMPLE_CATEGORY_RULES, SAMPLE_PRODUCTS

# class Command(BaseCommand):
#     help = 'Load sample data for attribute quality scoring'
    
#     def handle(self, *args, **kwargs):
#         self.stdout.write('Loading sample category rules...')
        
#         # Clear existing rules
#         CategoryAttributeRule.objects.all().delete()
        
#         # Load rules
#         for rule in SAMPLE_CATEGORY_RULES:
#             CategoryAttributeRule.objects.create(**rule)
        
#         self.stdout.write(self.style.SUCCESS(f'Loaded {len(SAMPLE_CATEGORY_RULES)} category rules'))
        
#         # Load products
#         self.stdout.write('Loading sample products...')
#         Product.objects.all().delete()
        
#         for prod in SAMPLE_PRODUCTS:
#             Product.objects.create(**prod)
        
#         self.stdout.write(self.style.SUCCESS(f'Loaded {len(SAMPLE_PRODUCTS)} products'))
#         self.stdout.write(self.style.SUCCESS('Sample data loaded successfully!'))





# management/commands/load_sample_data.py
"""
Django management command to load sample data
Run: python manage.py load_sample_data
"""
from django.core.management.base import BaseCommand
from core.models import Product, CategoryAttributeRule, ProductContentRule # <-- Import new model
from data.sample_data import SAMPLE_CATEGORY_RULES, SAMPLE_PRODUCTS, SAMPLE_CONTENT_RULES # <-- Import new data

class Command(BaseCommand):
    help = 'Load sample data for attribute quality scoring'

    def handle(self, *args, **kwargs):
        # --- Load Category Rules ---
        self.stdout.write('Loading sample category rules...')

        # Clear existing rules
        CategoryAttributeRule.objects.all().delete()

        # Load rules
        for rule in SAMPLE_CATEGORY_RULES:
            CategoryAttributeRule.objects.create(**rule)

        self.stdout.write(self.style.SUCCESS(f'Loaded {len(SAMPLE_CATEGORY_RULES)} category rules'))

        # --- Load Content Rules ---
        self.stdout.write('Loading sample content rules...')

        # Clear existing content rules
        ProductContentRule.objects.all().delete() # <-- Clear new rules

        # Load content rules
        for rule in SAMPLE_CONTENT_RULES:
            ProductContentRule.objects.create(**rule) # <-- Load new rules

        self.stdout.write(self.style.SUCCESS(f'Loaded {len(SAMPLE_CONTENT_RULES)} content rules'))


        # --- Load Products ---
        self.stdout.write('Loading sample products...')
        Product.objects.all().delete()

        for prod in SAMPLE_PRODUCTS:
            Product.objects.create(**prod)

        self.stdout.write(self.style.SUCCESS(f'Loaded {len(SAMPLE_PRODUCTS)} products'))
        self.stdout.write(self.style.SUCCESS('Sample data loaded successfully!'))