"""
Module for generic shapes.
"""
from point import Point
from turtle import Turtle

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

    corners - corners of this Shape
    perimeter - length to traverse corners
    area - area of this Shape
    """
    corners: [Point]
    perimeter: float
    area: float
    #TODO implement the __eq__ and __str__

    def __init__(self, corners: [Point])->None:
        """ Create a new Shape self with corners.

        Assume that the corners are traversed in order, that the sides are equal
        and the sides are of equal length, and the vertices are right angles.
        """
        # we want to copy of the corners list using [:] not reference to them
        # so that if we change them we do not change the original list user
        # provided
        self.corners = corners[:]
        # a private attribute _turtle
        self._turtle = Turtle()
        self._set_perimeter()
        self._set_area()

    def __str__(self) -> str:
        """
        returns string representation
        """
        str_points = ",".join(str(c) for c in self.corners)

        return type(self).__name__+"([{}])".format(str_points)
    def _set_perimeter(self)->None:
        """ Set Shape self's perimeter to the sum of the distances between
        corners.
        """
        distance_list = []
        for i in range(len(self.corners)):
            distance_list.append(self.corners[i].distance(self.corners[i-1]))
        self._perimeter = sum(distance_list)

    def _set_area(self)->None:
        """ Set the area of Shape self to the Shape of its sides.
        """
        self._area = -1.0
        raise NotImplementedError("Set area in subclass!!!")

    def get_perimeter(self)->float:
        """ Return the perimeter of this Shape
        """
        return self._perimeter

    def get_area(self)->float:
        """ Return the area of this Shape
        """
        return self._area

    # perimeter = property(_get_perimeter, None)
    # area = property(_get_area, None)

    def move_by(self, offset_point: Point)->None:
        """
        Move Shape self to a new position by adding Point offset_point to
        each corner.
        """
        self.corners = [c + offset_point for c in self.corners]
        # print('corners')
        # for x in self.corners:
        #     print(x)

    def draw(self)->None:
        """
        Draw Shape self.
        """
        self._turtle.penup()
        self._turtle.goto(self.corners[-1].x, self.corners[-1].y)
        # print('-1 stuff')
        # -1 in self.corners[-1] refers to the last element
        # print(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 = Shape([Point(0, 0)])
