#!/usr/bin/env python3
"""Cariflex - Create assets directly via FlexMeasures API using JWT token."""
import requests, json, uuid, sys

HOST = "https://flexmeasures.digitribe.fr"
API_VERSION = "v3_0"

# Get the admin user from DB and generate a password hash
import subprocess
result = subprocess.run([
    "docker", "exec", "flexmeasures-db", "psql", "-U", "flexmeasures", "-d", "flexmeasures",
    "-t", "-c", "SELECT password FROM fm_user WHERE email='admin@digitribe.fr';"
], capture_output=True, text=True)
print(f"Admin password hash: {result.stdout.strip()[:50]}...")

# Try to get auth token
# First, check what auth endpoints exist
for endpoint in [f"/api/{API_VERSION}/requestAuthToken", f"/api/{API_VERSION}/auth/token", f"/api/{API_VERSION}/login"]:
    r = requests.post(f"{HOST}{endpoint}", 
        json={"email": "admin@digitribe.fr", "password": "Digitribe972"},
        verify=False, timeout=10)
    print(f"{endpoint}: {r.status_code} - {r.text[:200]}")
