from dataclasses import dataclass

from verada import Annotated, Interval, requires

type Tally = Annotated[int, Interval(ge=0, le=1000)]

calls: Tally = 0


@dataclass
class Box:
    width: int

    def widen(self, k: int) -> None:
        requires(0 <= self.width <= 1000 and 0 <= k <= 1000)
        self.width += k


# a parameter is changed where the function passes it to one that changes it (Python's
# object is the same object): `outer` and `deeper` change their lists too, and `grow` its box
def inner(ys: list[int]) -> None:
    requires(len(ys) < 100)
    ys.append(4)


def outer(zs: list[int]) -> None:
    requires(len(zs) < 100)
    inner(zs)


def deeper(ws: list[int]) -> None:
    requires(len(ws) < 100)
    outer(ws)


def grow(b: Box) -> None:
    requires(0 <= b.width <= 1000)
    b.widen(3)


# `global`: the module's variable, which the function assigns
def count() -> None:
    global calls
    calls = (calls + 1) % 1000


def main() -> None:
    xs: list[int] = [1, 2, 3]
    deeper(xs)
    print(len(xs))
    print(3 in xs, 7 in xs, 7 not in xs)
    b = Box(width=1)
    grow(b)
    print(b.width)
    count()
    count()
    print(calls)


if __name__ == "__main__":
    main()
