"""The tool from video 3, as a plain Python function.

Name, a one-line docstring, typed inputs and a result. That's a tool.
In video 5 it moves into a hub's tools_local/ folder with @function_tool.
"""
import csv
from pathlib import Path

STOCK = Path(__file__).with_name("stock.csv")


def check_stock(title: str, branch: str) -> dict:
    """Copies on hand for one title at one branch."""
    with STOCK.open(newline="") as f:
        for row in csv.DictReader(f):
            if row["title"] == title and row["branch"] == branch:
                return {"copies": int(row["copies"]), "counted_at": row["counted_at"]}
    return {"error": "No stock record for that title and branch."}


if __name__ == "__main__":
    print(check_stock("Paper Moons", "Riverside"))
