#!/usr/bin/env python
"""
Clean up structure-based categories that were incorrectly created
This will remove categories like "Guide", "Article", etc. that match content_structure values
"""
import os
import sys
import django

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'igny8_core.settings')
django.setup()

from django.db import transaction
from igny8_core.business.content.models import ContentTaxonomy

# List of structure values that were incorrectly added as categories
STRUCTURE_VALUES = ['Guide', 'Article', 'Listicle', 'How To', 'Tutorial', 'Review', 'Comparison']

print("=" * 80)
print("CLEANING UP STRUCTURE-BASED CATEGORIES")
print("=" * 80)

for structure_name in STRUCTURE_VALUES:
    categories = ContentTaxonomy.objects.filter(
        taxonomy_type='category',
        name=structure_name
    )
    
    if categories.exists():
        count = categories.count()
        print(f"\nRemoving {count} '{structure_name}' categor{'y' if count == 1 else 'ies'}...")
        categories.delete()
        print(f"  ✓ Deleted {count} '{structure_name}' categor{'y' if count == 1 else 'ies'}")

print("\n" + "=" * 80)
print("CLEANUP COMPLETE")
print("=" * 80)
