"""
implement classes Square and RightAngleTriangle
"""
from turtle import Turtle
from point import Point
from typing import List
from time import sleep


class Square:
    """ A Square shape that can draw itself, move, and
    report area.

    corners - corners of square
    """
    corners: List[Point]

    # TODO: lots of examples, plus __str__, __eq__, are missing, fill them in!
    def __init__(self, corners: List[Point]):
        """ Create a new Square self with corners.

        Assume the corners are traversed in order, that
        the sides are of equal length, and that the vertices
        are right angles.
        """
        # shallow copy of corners
        self.corners = corners[:]
        # a private turtle...
        self._turtle = Turtle()

    def get_area(self) -> float:
        """ Set the area of Square self to the square of
        its sides.
        """
        return self.corners[0].distance_to(self.corners[1]) ** 2

    def move_by(self, offset_point: Point) -> None:
        """ Move Square self to a new position by adding
        Point offset_point to each corner.
        """
        # list comprehension
        # see lab2, bottom of page 1
        self.corners = [(c + offset_point) for c in self.corners]
        # equivalent to...
        # new_corners = []
        #  for c in self.corners:
        #     new_corners.append(c.add(offset_point))

    def draw(self) -> None:
        """ Draw Square self.
        """
        self._turtle.penup()
        self._turtle.goto(self.corners[-1].x, self.corners[-1].y)
        self._turtle.pendown()
        for i in range(len(self.corners)):
            self._turtle.goto(self.corners[i].x, self.corners[i].y)
        self._turtle.penup()
        self._turtle.goto(0, 0)


if __name__ == "__main__":
    import doctest
    doctest.testmod()
    s = Square([Point(0, 0), Point(100, 0), Point(100, 100), Point(0, 100)])
    s.draw()
    s.move_by(Point(100, 200))
    s.draw()
    sleep(5)
    print(s.get_area())
