"""
TMDb (The Movie Database) — Search Movie Demo
==============================================
A minimal, ready-to-run example of searching movies with TMDb.

Get an API key (free):
    1. Create an account at https://www.themoviedb.org/signup
    2. Go to Settings -> API (https://www.themoviedb.org/settings/api).
    3. Request an API key (choose "Developer") and copy the "API Read
       Access Token" or the v3 API key.

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

Run:
    python tmdb_demo.py
"""

import os
import requests


def search_movie(query: str) -> list:
    """Return 'Title (Year)' strings for movies matching the query."""
    response = requests.get(
        "https://api.themoviedb.org/3/search/movie",
        params={"query": query, "api_key": os.environ.get("TMDB_API_KEY")},
    )
    response.raise_for_status()
    out = []
    for m in response.json()["results"][:5]:
        year = (m.get("release_date") or "----")[:4]
        out.append(f"{m['title']} ({year})")
    return out


if __name__ == "__main__":
    for title in search_movie("The Matrix"):
        print(title)
