"""
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.

    === Attributes ===
    @type corners: list[Point]
       corners of this Shape
    @type perimeter: float
       length to traverse corners
    @type area: float
        area of this Shape
    """

    def __init__(self, corners):
        """ 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.

        @type self: Shape
        @type corners: list[Point]
        @rtype: None
        """
        self.corners = corners[:]
        self._turtle = Turtle()
        self._set_perimeter()
        self._set_area()

    def _set_perimeter(self):
        """ Set Shape self's perimeter to the sum of the distances between
        corners.

        @type self: Shape
        @rtype: None
        """
        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):
        """ Set the area of Shape self to the Shape of its sides.

        @type self: Shape
        @rtype: None
        """
        self._area = -1.0
        raise NotImplementedError("Set area in subclass!!!")

    def _get_perimeter(self):
        """ Return the perimeter of this Shape

        @type self: Shape
        @rtype: float
        """
        return self._perimeter

    def _get_area(self):
        """ Return the area of this Shape

        @type self: Shape
        @rtype: float
        """
        return self._area

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

    def move_by(self, offset_point):
        """
        Move Shape self to a new position by adding Point offset_point to
        each corner.

        @type self: Shape
        @type offset_point: Point
        @rtype: None
        """
        self.corners = [c + offset_point for c in self.corners]

    def draw(self):
        """
        Draw Shape self.

        @type self: Shape
        @rtype: None
        """
        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 = Shape([Point(0, 0)])
