#!/usr/bin/env python3
"""How many equal-length tags fit in 500 under the rule, and the boundary lists for checking them in the tool.
Usage: capacity.py table | capacity.py cases > capacity-cases.json"""
import json, sys
def cost(t): return len(t) + (2 if " " in t else 0)
def total(tags): return sum(cost(t) for t in tags) + max(0, len(tags) - 1)
SHAPES = [("single word, 4 letters", "abcd"), ("single word, 6 letters", "abcdef"), ("single word, 8 letters", "abcdefgh"),
          ("single word, 12 letters", "abcdefghijkl"), ("two words, 4+4 letters", "abcd efgh"), ("two words, 6+6 letters", "abcdef ghijkl")]
def fits(tag):
    n = 0
    while total([tag] * (n + 1)) <= 500: n += 1
    return n
if sys.argv[1] == "table":
    for name, tag in SHAPES:
        n = fits(tag)
        print(f"{name} | tag costs {cost(tag)} | {n} tags fit ({total([tag]*n)} characters) | {n+1} tags = {total([tag]*(n+1))}")
else:
    out = []
    for name, tag in SHAPES:
        n = fits(tag)
        out.append({"name": f"{name}: {n} tags", "text": ",".join([tag] * n)})
        out.append({"name": f"{name}: {n+1} tags", "text": ",".join([tag] * (n + 1))})
    print(json.dumps(out, ensure_ascii=False))
