# Python's classes as Vibe takes them (D188): a dataclass's repr, special methods, a plain
# class with `__init__`, `@property` and `ClassVar`, an `Enum` class by value, by name and
# iterated, and an abstract dataclass base with fields. Its output is CPython's.
from abc import ABC, abstractmethod
from dataclasses import dataclass
from enum import Enum
from typing import ClassVar

from verada import requires


class Color(Enum):
    RED = 1
    GREEN = 2
    BLUE = 3


@dataclass
class Point:
    x: int
    y: int
    label: str
    shade: Color


@dataclass
class V:
    x: int

    def __str__(self) -> str:
        return f"V<{self.x}>"

    def __lt__(self, other: "V") -> bool:
        return self.x < other.x

    def __eq__(self, other: "V") -> bool:
        return self.x == other.x

    def __add__(self, other: "V") -> "V":
        requires(-1000 <= self.x <= 1000 and -1000 <= other.x <= 1000)
        return V(self.x + other.x)

    def __len__(self) -> int:
        return 1 if self.x == 0 else 2


class Counter:
    created: ClassVar[int] = 0

    def __init__(self, start: int, step: int = 1) -> None:
        self.n = start
        self.step = step

    def advance(self) -> None:
        if 0 <= self.n <= 1000 and 0 <= self.step <= 10:
            self.n += self.step

    @property
    def doubled(self) -> int:
        return self.n * 2 if 0 <= self.n <= 1000 else 0


@dataclass
class Shape(ABC):
    tag: int

    @abstractmethod
    def area(self) -> int:
        pass


@dataclass
class Square(Shape):
    side: int

    def area(self) -> int:
        return self.side * self.side if 0 <= self.side <= 1000 else 0


def main() -> None:
    p = Point(1, 2, "p", Color.GREEN)
    print(p, str(p), repr(p), f"{p}")
    print(str(V(1)), V(1) < V(2), V(3) == V(3), V(1) + V(2), len(V(0)), len(V(5)))
    c = Counter(3)
    d = c
    d.advance()
    e = Counter(10, 5)
    e.advance()
    print(c.n, c.doubled, e.n, Counter.created)
    print(Color(3), Color["RED"], len(Color), Color(2).name)
    for m in Color:
        print(m.name, m.value)
    q = Square(7, 3)
    print(q.tag, q.area(), q)


if __name__ == "__main__":
    main()
