#!/usr/bin/env bash
set -euo pipefail

USERNAME="$(grep '^PHENOCRYPTO_USERNAME=' /etc/phenocrypto.env | cut -d= -f2-)"
PASSWORD="$(grep '^PHENOCRYPTO_PASSWORD=' /etc/phenocrypto.env | cut -d= -f2-)"
COOKIE="/tmp/phenocrypto-dummy-api-cookies.txt"

curl -kfsS \
  -c "$COOKIE" \
  -H "Content-Type: application/json" \
  -d "{\"username\":\"$USERNAME\",\"password\":\"$PASSWORD\"}" \
  "https://muxiyeto.com/phenocrypto/api/login" \
  >/tmp/phenocrypto-dummy-login.json

curl -kfsS \
  -b "$COOKIE" \
  -H "Content-Type: application/json" \
  -d '{"api_key":"DUMMY_TEST_KRAKEN_API_KEY_DO_NOT_TRADE","api_secret":"DUMMY_TEST_KRAKEN_API_SECRET_DO_NOT_TRADE"}' \
  "https://muxiyeto.com/phenocrypto/api/credentials" \
  >/tmp/phenocrypto-dummy-credentials.json

python3 - <<'PY'
import json
from pathlib import Path

payload = json.loads(Path("/tmp/phenocrypto-dummy-credentials.json").read_text())
print(f"ok={payload['ok']}")
print(f"has_api_key={payload['credentials']['has_api_key']}")
print(f"has_api_secret={payload['credentials']['has_api_secret']}")
print(f"storage={payload['credentials']['storage']}")
PY
