[Unit]
Description=HVAC TikTok Caption Fetcher (Overnight Job)
After=network.target

[Service]
Type=oneshot
# Service user - should be configured during installation
User=%i
Group=%i
WorkingDirectory=/opt/hvac-kia-content
Environment="PATH=/usr/local/bin:/usr/bin:/bin"
Environment="DISPLAY=:0"
Environment="XAUTHORITY=/run/user/1000/.mutter-Xwaylandauth.90WDB3"

# Load environment variables (includes DISPLAY/XAUTHORITY for TikTok)
EnvironmentFile=/opt/hvac-kia-content/.env

# Run the caption fetcher
ExecStart=/usr/local/bin/python3 /opt/hvac-kia-content/run_production.py --job tiktok-captions

# Longer timeout for caption fetching
TimeoutStartSec=3600

# Don't restart on failure (avoid hammering TikTok)
Restart=no

# Logging
StandardOutput=append:/var/log/hvac-content/tiktok-captions.log
StandardError=append:/var/log/hvac-content/tiktok-captions-error.log

[Install]
WantedBy=multi-user.target