"""Order call classes.

These classes implement any response cleaning and validation needed.  If a
call class isn't defined for a given method then one is created using
ubersmith.calls.BaseCall.

"""

from ubersmith.calls import BaseCall, GroupCall, _rename_key
from ubersmith.utils import prepend_base

__all__ = [
    'GetCall',
    'ListCall',
]

_ = prepend_base(__name__.split('.')[-1])


class GetCall(BaseCall):
    method = _('get')
    required_fields = [('order_id', 'hash')]


class ListCall(GroupCall):
    method = _('list')
    int_fields = ['order_id', 'priority', 'order_status', 'client_id',
                  'order_from_id', 'order_queue_id', 'opportunity_id']
    decimal_fields = ['total']
    timestamp_fields = ['activity', 'ts']


class QueueListCall(GroupCall):
    method = _('queue_list')
    required_fields = ['brand_id']

    def clean(self):
        super(QueueListCall, self).clean()
        # clean additional stuff that is nested in the response
        for value in self.cleaned.values():
            for k, v in value['steps'].items():
                _rename_key(value['steps'], k, int(k))
                v['count'] = int(v['count'])

@@ -254,17 +254,28 @@
 name_key
+, _CLEANERS
 %0A
-
 from ube
@@ -351,16 +351,37 @@
 tCall',%0A
+    'QueueListCall',%0A
 %5D%0A%0A_ = p
@@ -511,16 +511,550 @@
 hash')%5D%0A
+    int_fields = %5B'order_id', 'priority', 'order_status', 'client_id',%0A                  'order_form_id', 'order_queue_id', 'opportunity_id',%0A                  'owner'%5D%0A    decimal_fields = %5B'total'%5D%0A    timestamp_fields = %5B'activity', 'ts'%5D%0A%0A    def clean(self):%0A        super(GetCall, self).clean()%0A        # clean additional stuff that is nested in the response%0A        for k, v in self.cleaned%5B'progress'%5D.items():%0A            _rename_key(self.cleaned%5B'progress'%5D, k, int(k))%0A            v%5B'ts'%5D = _CLEANERS%5B'timestamp'%5D(v%5B'ts'%5D)%0A
 %0A%0Aclass 
@@ -1194,18 +1194,18 @@
 'order_f
-r
 o
+r
 m_id', '
@@ -1237,16 +1237,43 @@
 nity_id'
+,%0A                  'owner'
 %5D%0A    de

add additional cleaning to order.get fix int fields on order.list and add order.queue_list to module __all__