"""Vérification du template SneakSafe sur Shopify"""

import json
import requests

# Lecture du token
with open(r"C:\ASSISTANT_IA\.env") as f:
    for line in f:
        if line.startswith("SHOPIFY_ACCESS_TOKEN="):
            token = line.strip().split("=", 1)[1]
            break

headers = {
    "X-Shopify-Access-Token": token,
    "Content-Type": "application/json"
}

# Récupérer le template depuis Shopify
r = requests.get(
    "https://vs1j6z-j0.myshopify.com/admin/api/2024-01/themes/134782386382/assets.json?asset[key]=templates/product.sneaksafe.json",
    headers=headers
)

if r.status_code == 200:
    data = r.json()
    template = data['asset']['value']
    template_json = json.loads(template)

    print("Vérification du template SneakSafe sur Shopify")
    print("=" * 70)

    # Vérifier les images clés
    main_image = template_json['sections']['kQnD7wNPec']['settings']['mainImage_media_video']
    gallery_image = template_json['sections']['kQnD7wNPec']['settings']['productImagesGalleryImage_media_video']

    print(f"\n1. Image principale (mainImage_media_video) :")
    print(f"   {main_image}")
    if 'packshot_trio_vrai' in main_image:
        print("   ✓ VRAIE PHOTO (packshot trio)")
    elif 'hero-studio' in main_image:
        print("   ✗ RENDU CGI (PROBLÈME !)")

    print(f"\n2. Image galerie (productImagesGalleryImage_media_video) :")
    print(f"   {gallery_image}")
    if 'packshot_gris_vrai' in gallery_image:
        print("   ✓ VRAIE PHOTO (packshot gris)")
    elif 'chenille-360' in gallery_image:
        print("   ✗ RENDU CGI (PROBLÈME !)")

    # Chercher toutes les occurrences de rendus CGI
    cgi_images = []
    if 'hero-studio' in template:
        cgi_images.append('hero-studio.png')
    if 'chenille-360' in template:
        cgi_images.append('chenille-360.png')

    print(f"\n3. Recherche globale de rendus CGI restants :")
    if cgi_images:
        print(f"   ✗ PROBLÈME : {len(cgi_images)} rendu(s) CGI trouvé(s) :")
        for img in cgi_images:
            print(f"     - {img}")
    else:
        print("   ✓ Aucun rendu CGI trouvé")

    print(f"\n4. Vérification des vraies photos :")
    packshot_count = template.count('packshot') + template.count('vrai')
    print(f"   Occurrences de 'packshot' ou 'vrai' : {packshot_count}")
    if packshot_count >= 4:
        print("   ✓ Toutes les images semblent remplacées")
    else:
        print(f"   ⚠ Seulement {packshot_count} occurrences (attendu : 4+)")

else:
    print(f"Erreur {r.status_code} : {r.text}")
