from verada import invariant

import scores
from people import Person, first_name, greeting
from graphs import Graph, Node, dist_of, visit, visited_count
from scores import Percent, best, passing, passing_points, raise_to, record, spread, sum_of, total
from words import count_words


def main() -> None:
    round_one: list[int] = [72, 85, 64, 91, 58]
    print(f"{len(round_one)} scores, total {total(round_one)}")
    top = best(round_one)
    print(f"best: score {round_one[top]} at position {top}")
    low, high = spread(round_one)
    print(f"from {low} to {high}")
    print("passing 70:", passing(round_one, 70))
    marks: list[Percent] = [72, 85, 64]
    print("sums:", sum_of(marks), passing_points(marks, 70))
    raise_to(round_one, 65)
    print("raised:", round_one[2], round_one[4])
    record(round_one, 99)
    print("after the late entry:", len(round_one), "scores, best", round_one[best(round_one)])
    squares: list[int] = [n * n for n in range(10) if n % 3 == 0]
    for s in squares:
        print(s)
    kept: list[int] = squares.copy()
    largest: int = squares.pop()
    print(f"popped {largest}, {len(squares)} left, {len(kept)} kept")
    # inserting before a position, and taking one out of the middle, from 0 as Python counts
    queue: list[int] = [5, 6, 7]
    queue.insert(1, 9)
    queue.insert(4, 8)
    first: int = queue.pop(0)
    middle: int = queue.pop(1)
    print(f"took {first} and {middle}, left {queue[0]} {queue[1]} {queue[2]}")
    kept.extend(squares)
    print("extended:", len(kept), kept[len(kept) - 1])
    # the year each of three runners finished, by bib number
    finished: dict[int, int] = {7: 2019, 3: 2021}
    finished[12] = 2020
    finished[7] = 2018
    print(len(finished), finished[7], 12 in finished, 5 in finished)
    for bib in finished:
        print(bib, finished[bib])
    seen: set[int] = {3, 1}
    seen.add(2)
    seen.add(3)
    print(len(seen), 2 in seen, 5 not in seen)
    for x in seen:
        print(x)
    third = 1.0 / 3.0
    print("floats:", third, float(len(round_one)) / 4.0)
    name = "Vibe"
    print(f"{name[0]} is the first of {len(name)} letters; {{braces}} stay")
    g = Graph(nodes=[])
    g.nodes.append(Node(visited=False, dist=0))
    g.nodes.append(Node(visited=False, dist=0))
    visit(g, 1, 7)
    print(len(g.nodes), g.nodes[1].visited, g.nodes[1].dist, g.nodes[0].visited)
    # int() truncates toward zero, as Python's does (Ada's conversion would round)
    print(int(third * 10.0), int(-third * 10.0), int(len(round_one)))
    by_id: dict[int, Node] = {7: Node(visited=True, dist=3)}
    by_id[8] = Node(visited=False, dist=1)
    print(dist_of(by_id, 7), len(by_id), visited_count(by_id))
    # strings in records and lists: texts, copied as other values are
    ann = Person(name="Ann", age=3)
    bob = Person(name="Bob", age=4)
    bob.name = "Robert"
    who = "Cy"
    print(ann.name, bob.name, greeting(ann), len(bob.name), ann.name == "Ann")
    names: list[str] = [ann.name, who]
    names.append(bob.name)
    print(len(names), first_name(names), names[2])
    # a word count: texts as keys, in the order they first appear
    text: list[str] = ["the", "cat", "saw", "the", "other", "cat", "the"]
    counts: dict[str, int] = count_words(text)
    if "the" in counts:
        print(len(counts), counts["the"], "dog" in counts)
    for w in counts:
        print(w, counts[w])
