# coding=utf-8
"""
This code was generated by
\ / _    _  _|   _  _
 | (_)\/(_)(_|\/| |(/_  v1.0.0
      /       /       
"""

from twilio import values
from twilio.instance_context import InstanceContext
from twilio.instance_resource import InstanceResource
from twilio.list_resource import ListResource
from twilio.page import Page


class UsageList(ListResource):

    def __init__(self, version, device_sid):
        """
        Initialize the UsageList
        
        :param Version version: Version that contains the resource
        :param device_sid: The device_sid
        
        :returns: UsageList
        :rtype: UsageList
        """
        super(UsageList, self).__init__(version)
        
        # Path Solution
        self._solution = {
            'device_sid': device_sid,
        }

    def get(self):
        """
        Constructs a UsageContext
        
        :returns: UsageContext
        :rtype: UsageContext
        """
        return UsageContext(
            self._version,
            device_sid=self._solution['device_sid'],
        )

    def __call__(self):
        """
        Constructs a UsageContext
        
        :returns: UsageContext
        :rtype: UsageContext
        """
        return UsageContext(
            self._version,
            device_sid=self._solution['device_sid'],
        )

    def __repr__(self):
        """
        Provide a friendly representation
        
        :returns: Machine friendly representation
        :rtype: str
        """
        return '<Twilio.Preview.Wireless.UsageList>'


class UsagePage(Page):

    def __init__(self, version, response, solution):
        """
        Initialize the UsagePage
        
        :param Version version: Version that contains the resource
        :param Response response: Response from the API
        :param device_sid: The device_sid
        
        :returns: UsagePage
        :rtype: UsagePage
        """
        super(UsagePage, self).__init__(version, response)
        
        # Path Solution
        self._solution = solution

    def get_instance(self, payload):
        """
        Build an instance of UsageInstance
        
        :param dict payload: Payload response from the API
        
        :returns: UsageInstance
        :rtype: UsageInstance
        """
        return UsageInstance(
            self._version,
            payload,
            device_sid=self._solution['device_sid'],
        )

    def __repr__(self):
        """
        Provide a friendly representation
        
        :returns: Machine friendly representation
        :rtype: str
        """
        return '<Twilio.Preview.Wireless.UsagePage>'


class UsageContext(InstanceContext):

    def __init__(self, version, device_sid):
        """
        Initialize the UsageContext
        
        :param Version version: Version that contains the resource
        :param device_sid: The device_sid
        
        :returns: UsageContext
        :rtype: UsageContext
        """
        super(UsageContext, self).__init__(version)
        
        # Path Solution
        self._solution = {
            'device_sid': device_sid,
        }
        self._uri = '/Devices/{device_sid}/Usage'.format(**self._solution)

    def fetch(self, end=values.unset, start=values.unset):
        """
        Fetch a UsageInstance
        
        :param unicode end: The end
        :param unicode start: The start
        
        :returns: Fetched UsageInstance
        :rtype: UsageInstance
        """
        params = values.of({
            'End': end,
            'Start': start,
        })
        
        payload = self._version.fetch(
            'GET',
            self._uri,
            params=params,
        )
        
        return UsageInstance(
            self._version,
            payload,
            device_sid=self._solution['device_sid'],
        )

    def __repr__(self):
        """
        Provide a friendly representation
        
        :returns: Machine friendly representation
        :rtype: str
        """
        context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items())
        return '<Twilio.Preview.Wireless.UsageContext {}>'.format(context)


class UsageInstance(InstanceResource):

    def __init__(self, version, payload, device_sid):
        """
        Initialize the UsageInstance
        
        :returns: UsageInstance
        :rtype: UsageInstance
        """
        super(UsageInstance, self).__init__(version)
        
        # Marshaled Properties
        self._properties = {
            'device_sid': payload['device_sid'],
            'device_alias': payload['device_alias'],
            'account_sid': payload['account_sid'],
            'period': payload['period'],
            'commands_usage': payload['commands_usage'],
            'commands_costs': payload['commands_costs'],
            'data_usage': payload['data_usage'],
            'data_costs': payload['data_costs'],
            'url': payload['url'],
        }
        
        # Context
        self._context = None
        self._solution = {
            'device_sid': device_sid,
        }

    @property
    def _proxy(self):
        """
        Generate an instance context for the instance, the context is capable of
        performing various actions.  All instance actions are proxied to the context
        
        :returns: UsageContext for this UsageInstance
        :rtype: UsageContext
        """
        if self._context is None:
            self._context = UsageContext(
                self._version,
                device_sid=self._solution['device_sid'],
            )
        return self._context

    @property
    def device_sid(self):
        """
        :returns: The device_sid
        :rtype: unicode
        """
        return self._properties['device_sid']

    @property
    def device_alias(self):
        """
        :returns: The device_alias
        :rtype: unicode
        """
        return self._properties['device_alias']

    @property
    def account_sid(self):
        """
        :returns: The account_sid
        :rtype: unicode
        """
        return self._properties['account_sid']

    @property
    def period(self):
        """
        :returns: The period
        :rtype: dict
        """
        return self._properties['period']

    @property
    def commands_usage(self):
        """
        :returns: The commands_usage
        :rtype: dict
        """
        return self._properties['commands_usage']

    @property
    def commands_costs(self):
        """
        :returns: The commands_costs
        :rtype: dict
        """
        return self._properties['commands_costs']

    @property
    def data_usage(self):
        """
        :returns: The data_usage
        :rtype: dict
        """
        return self._properties['data_usage']

    @property
    def data_costs(self):
        """
        :returns: The data_costs
        :rtype: dict
        """
        return self._properties['data_costs']

    @property
    def url(self):
        """
        :returns: The url
        :rtype: unicode
        """
        return self._properties['url']

    def fetch(self, end=values.unset, start=values.unset):
        """
        Fetch a UsageInstance
        
        :param unicode end: The end
        :param unicode start: The start
        
        :returns: Fetched UsageInstance
        :rtype: UsageInstance
        """
        return self._proxy.fetch(
            end=end,
            start=start,
        )

    def __repr__(self):
        """
        Provide a friendly representation
        
        :returns: Machine friendly representation
        :rtype: str
        """
        context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items())
        return '<Twilio.Preview.Wireless.UsageInstance {}>'.format(context)
