#!/usr/bin/env python3
"""Test image attachment setting (enable/disable)"""

import sys
import json
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent))
sys.path.insert(0, str(Path(__file__).parent / 'modules'))

from modules.pushover_notifier import PushoverNotifier

def load_config():
    config_path = Path(__file__).parent / 'config' / 'settings.json'
    with open(config_path, 'r') as f:
        return json.load(f)

# Load config
config = load_config()
pushover_config = config.get('pushover', {})

# Test images
test_images = [
    "/opt/immich/md/forums/PicturePub/Teri Hatcher & Eva Longoria - Desperate Housewives S08E14_ Get Out of My Life 2012, 80x/638100294_rere-12.jpg",
    "/opt/immich/md/forums/PicturePub/Teri Hatcher & Eva Longoria - Desperate Housewives S08E14_ Get Out of My Life 2012, 80x/638100582_rere-194.jpg"
]

# Prepare test downloads
downloads = []
for i in range(3):
    downloads.append({
        'source': 'evalongoria',
        'content_type': 'post',
        'filename': f'post_{i}.jpg',
        'file_path': test_images[i % len(test_images)]
    })

print("=" * 60)
print("Test 1: Image Thumbnails ENABLED")
print("=" * 60)

# Create notifier with images enabled
notifier1 = PushoverNotifier(
    user_key=pushover_config.get('user_key'),
    api_token=pushover_config.get('api_token'),
    enabled=True,
    include_image=True  # ENABLED
)

print("Sending notification WITH image attachment...")
success1 = notifier1.notify_batch_download(
    platform='instagram',
    downloads=downloads,
    search_term=None
)

print(f"{'✅' if success1 else '❌'} Notification sent (with image): {success1}")
print()

print("=" * 60)
print("Test 2: Image Thumbnails DISABLED")
print("=" * 60)

# Create notifier with images disabled
notifier2 = PushoverNotifier(
    user_key=pushover_config.get('user_key'),
    api_token=pushover_config.get('api_token'),
    enabled=True,
    include_image=False  # DISABLED
)

print("Sending notification WITHOUT image attachment...")
success2 = notifier2.notify_batch_download(
    platform='instagram',
    downloads=downloads,
    search_term=None
)

print(f"{'✅' if success2 else '❌'} Notification sent (without image): {success2}")
print()

print("=" * 60)
print("Test 3: Loading from Config File")
print("=" * 60)

from modules.pushover_notifier import create_notifier_from_config

notifier3 = create_notifier_from_config(config)

if notifier3:
    print(f"Notifier created from config")
    print(f"  - include_image setting: {notifier3.include_image}")
    print(f"  - Current config value: {pushover_config.get('include_image', True)}")
    print()

    print("Sending notification using config setting...")
    success3 = notifier3.notify_batch_download(
        platform='instagram',
        downloads=downloads,
        search_term=None
    )

    print(f"{'✅' if success3 else '❌'} Notification sent: {success3}")
else:
    print("❌ Failed to create notifier from config")

print()
print("=" * 60)
print("Check your Pushover app!")
print("You should see:")
print("  1. First notification WITH thumbnail")
print("  2. Second notification WITHOUT thumbnail")
print("  3. Third notification based on config setting")
print("=" * 60)
