#!/bin/bash

# Required environment variables
required_vars=("BOT_ROOT" "BOT_INSTAGRAM_ID" "BOT_INSTAGRAM_PASSWD" "BOT_KEY" "BOT_WEBHOOK_URL")

# Check for missing environment variables
missing_vars=()
for var in "${required_vars[@]}"; do
    if [ -z "${!var}" ]; then
        missing_vars+=("$var")
    fi
done

if [ ${#missing_vars[@]} -ne 0 ]; then
    echo "Error: Missing required environment variables:"
    printf '%s\n' "${missing_vars[@]}"
    exit 1
fi

# Generate config.json
cat > config.json << EOF
{
    "ROOT": "${BOT_ROOT}",
    "INSTAGRAM_ID": "${BOT_INSTAGRAM_ID}",
    "INSTAGRAM_PASSWORD": "${BOT_INSTAGRAM_PASSWORD}",
    "KEY": "${BOT_KEY}",
    "WEBHOOK_URL": "${BOT_WEBHOOK_URL}"
}
EOF

echo "Successfully generated config.json"
