# -*- coding: utf-8 -*-

import collections

import marshmallow
from marshmallow import fields

from mfit_service import resources
from mfit_service import views


class Programs(views.Base):

    id = fields.Integer(attribute='workout_movement_id')
    sets = fields.Integer()
    value = fields.Integer()
    unit = fields.String(attribute='unit_name')
    sort_order = fields.Integer()

    relationships = fields.Dict()

    @marshmallow.pre_dump
    def preprocess_unit(self, entity):
        entity.unit_name = entity.workout_movement_unit.name
        return entity

    @marshmallow.pre_dump
    def preprocess_relationships(self, entity):
        entity.relationships = collections.OrderedDict()
        entity.relationships['workouts_uri'] = resources.Workouts.get_self_link(
            workout=entity.workout)
        entity.relationships['movements_uri'] = resources.Movements.get_self_link(
            movement=entity.movement)
        return entity


@@ -728,22 +728,23 @@
 nships%5B'
-workou
+movemen
 ts_uri'%5D
@@ -760,14 +760,15 @@
 ces.
-Workou
+Movemen
 ts.g
@@ -793,22 +793,23 @@
         
-workou
+movemen
 t=entity
@@ -809,22 +809,23 @@
 =entity.
-workou
+movemen
 t)%0A     
@@ -841,39 +841,38 @@
 .relationships%5B'
-movemen
+workou
 ts_uri'%5D = resou
@@ -868,39 +868,38 @@
 i'%5D = resources.
-Movemen
+Workou
 ts.get_self_link
@@ -904,39 +904,38 @@
 nk(%0A            
-movemen
+workou
 t=entity.movemen
@@ -919,39 +919,38 @@
  workout=entity.
-movemen
+workou
 t)%0A        retur

Changed sort order to be alphabetical