#!/usr/bin/env python3
"""A small local literary calculator for a fictional household inventory."""

from __future__ import annotations

import json
from pathlib import Path
from typing import TypedDict, cast

DATA_FILE = Path(__file__).with_name("objects.json")


class ObjectRecord(TypedDict):
    name: str
    uses: int
    repairs: int
    sentiment: int
    dust: int


def attention_score(item: ObjectRecord) -> int:
    """Prefer use and repair history over sentiment alone."""
    return (
        int(item["uses"]) * 2
        + int(item["repairs"]) * 5
        + int(item["sentiment"])
        - int(item["dust"])
    )


def verdict(score: int) -> str:
    if score >= 20:
        return "keep within reach"
    if score >= 10:
        return "give a season of probation"
    return "release from committee"


def main() -> None:
    raw_objects = json.loads(DATA_FILE.read_text(encoding="utf-8"))
    objects = cast(list[ObjectRecord], raw_objects)
    rows = sorted(objects, key=attention_score, reverse=True)

    print("THE ATTENTION LEDGER")
    print("A fictional sorting exercise; no object has been judged in real life.\n")
    for item in rows:
        score = attention_score(item)
        print(f"{item['name']:<24} {score:>3}  {verdict(score)}")


if __name__ == "__main__":
    main()
