#!/usr/bin/env python
"""
Final verification that the WordPress content types are properly synced
"""
import os
import django

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'igny8_core.settings')
django.setup()

from igny8_core.business.integration.models import SiteIntegration
from igny8_core.auth.models import Site
import json

print("=" * 70)
print("WORDPRESS SYNC FIX VERIFICATION")
print("=" * 70)

# Get site 5
site = Site.objects.get(id=5)
print(f"\n✓ Site: {site.name} (ID: {site.id})")

# Get WordPress integration
integration = SiteIntegration.objects.get(site=site, platform='wordpress')
print(f"✓ Integration: {integration.platform.upper()} (ID: {integration.id})")
print(f"✓ Active: {integration.is_active}")
print(f"✓ Sync Enabled: {integration.sync_enabled}")

# Verify config data
config = integration.config_json or {}
content_types = config.get('content_types', {})

print("\n" + "=" * 70)
print("CONTENT TYPES STRUCTURE")
print("=" * 70)

# Post Types
post_types = content_types.get('post_types', {})
print(f"\n📝 Post Types: ({len(post_types)} total)")
for pt_name, pt_data in post_types.items():
    print(f"  • {pt_data['label']} ({pt_name})")
    print(f"    - Count: {pt_data['count']}")
    print(f"    - Enabled: {pt_data['enabled']}")
    print(f"    - Fetch Limit: {pt_data['fetch_limit']}")

# Taxonomies
taxonomies = content_types.get('taxonomies', {})
print(f"\n🏷️  Taxonomies: ({len(taxonomies)} total)")
for tax_name, tax_data in taxonomies.items():
    print(f"  • {tax_data['label']} ({tax_name})")
    print(f"    - Count: {tax_data['count']}")
    print(f"    - Enabled: {tax_data['enabled']}")
    print(f"    - Fetch Limit: {tax_data['fetch_limit']}")

# Last fetch time
last_fetch = content_types.get('last_structure_fetch')
print(f"\n🕐 Last Structure Fetch: {last_fetch}")

print("\n" + "=" * 70)
print("✅ SUCCESS! WordPress content types are properly configured")
print("=" * 70)
print("\nNext Steps:")
print("1. Refresh the IGNY8 app page in your browser")
print("2. Navigate to Sites → Settings → Content Types tab")
print("3. You should now see all Post Types and Taxonomies listed")
print("=" * 70)

