"""
ExchangeRate-API — Currency Conversion Demo
============================================
A minimal, ready-to-run example of converting between currencies.

Get an API key (free tier):
    1. Sign up at https://www.exchangerate-api.com (free plan, no card).
    2. Your API key is shown on the dashboard after you confirm your email.

Setup:
    pip install requests
    export EXCHANGERATE_API_KEY="..."

Run:
    python exchangerate_demo.py
"""

import os
import requests


def convert(amount: float, base: str, target: str) -> float:
    """Convert an amount from one currency to another."""
    key = os.environ.get("EXCHANGERATE_API_KEY")
    response = requests.get(
        f"https://v6.exchangerate-api.com/v6/{key}/pair/{base}/{target}/{amount}"
    )
    response.raise_for_status()
    return response.json()["conversion_result"]


if __name__ == "__main__":
    result = convert(100, "USD", "THB")
    print(f"100 USD = {result} THB")
