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

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


class FeedbackSummaryList(ListResource):

    def __init__(self, version, account_sid):
        """
        Initialize the FeedbackSummaryList

        :param Version version: Version that contains the resource
        :param account_sid: The SID of the Account that created this resource

        :returns: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryList
        :rtype: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryList
        """
        super(FeedbackSummaryList, self).__init__(version)

        # Path Solution
        self._solution = {'account_sid': account_sid, }
        self._uri = '/Accounts/{account_sid}/Calls/FeedbackSummary.json'.format(**self._solution)

    def create(self, start_date, end_date, include_subaccounts=values.unset,
               status_callback=values.unset, status_callback_method=values.unset):
        """
        Create the FeedbackSummaryInstance

        :param date start_date: Only include feedback given on or after this date
        :param date end_date: Only include feedback given on or before this date
        :param bool include_subaccounts: `true` includes feedback from the specified account and its subaccounts
        :param unicode status_callback: The URL that we will request when the feedback summary is complete
        :param unicode status_callback_method: The HTTP method we use to make requests to the StatusCallback URL

        :returns: The created FeedbackSummaryInstance
        :rtype: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryInstance
        """
        data = values.of({
            'StartDate': serialize.iso8601_date(start_date),
            'EndDate': serialize.iso8601_date(end_date),
            'IncludeSubaccounts': include_subaccounts,
            'StatusCallback': status_callback,
            'StatusCallbackMethod': status_callback_method,
        })

        payload = self._version.create(method='POST', uri=self._uri, data=data, )

        return FeedbackSummaryInstance(self._version, payload, account_sid=self._solution['account_sid'], )

    def get(self, sid):
        """
        Constructs a FeedbackSummaryContext

        :param sid: A string that uniquely identifies this feedback summary resource

        :returns: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryContext
        :rtype: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryContext
        """
        return FeedbackSummaryContext(self._version, account_sid=self._solution['account_sid'], sid=sid, )

    def __call__(self, sid):
        """
        Constructs a FeedbackSummaryContext

        :param sid: A string that uniquely identifies this feedback summary resource

        :returns: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryContext
        :rtype: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryContext
        """
        return FeedbackSummaryContext(self._version, account_sid=self._solution['account_sid'], sid=sid, )

    def __repr__(self):
        """
        Provide a friendly representation

        :returns: Machine friendly representation
        :rtype: str
        """
        return '<Twilio.Api.V2010.FeedbackSummaryList>'


class FeedbackSummaryPage(Page):

    def __init__(self, version, response, solution):
        """
        Initialize the FeedbackSummaryPage

        :param Version version: Version that contains the resource
        :param Response response: Response from the API
        :param account_sid: The SID of the Account that created this resource

        :returns: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryPage
        :rtype: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryPage
        """
        super(FeedbackSummaryPage, self).__init__(version, response)

        # Path Solution
        self._solution = solution

    def get_instance(self, payload):
        """
        Build an instance of FeedbackSummaryInstance

        :param dict payload: Payload response from the API

        :returns: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryInstance
        :rtype: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryInstance
        """
        return FeedbackSummaryInstance(self._version, payload, account_sid=self._solution['account_sid'], )

    def __repr__(self):
        """
        Provide a friendly representation

        :returns: Machine friendly representation
        :rtype: str
        """
        return '<Twilio.Api.V2010.FeedbackSummaryPage>'


class FeedbackSummaryContext(InstanceContext):

    def __init__(self, version, account_sid, sid):
        """
        Initialize the FeedbackSummaryContext

        :param Version version: Version that contains the resource
        :param account_sid: The unique sid that identifies this account
        :param sid: A string that uniquely identifies this feedback summary resource

        :returns: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryContext
        :rtype: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryContext
        """
        super(FeedbackSummaryContext, self).__init__(version)

        # Path Solution
        self._solution = {'account_sid': account_sid, 'sid': sid, }
        self._uri = '/Accounts/{account_sid}/Calls/FeedbackSummary/{sid}.json'.format(**self._solution)

    def fetch(self):
        """
        Fetch the FeedbackSummaryInstance

        :returns: The fetched FeedbackSummaryInstance
        :rtype: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryInstance
        """
        payload = self._version.fetch(method='GET', uri=self._uri, )

        return FeedbackSummaryInstance(
            self._version,
            payload,
            account_sid=self._solution['account_sid'],
            sid=self._solution['sid'],
        )

    def delete(self):
        """
        Deletes the FeedbackSummaryInstance

        :returns: True if delete succeeds, False otherwise
        :rtype: bool
        """
        return self._version.delete(method='DELETE', uri=self._uri, )

    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.Api.V2010.FeedbackSummaryContext {}>'.format(context)


class FeedbackSummaryInstance(InstanceResource):

    class Status(object):
        QUEUED = "queued"
        IN_PROGRESS = "in-progress"
        COMPLETED = "completed"
        FAILED = "failed"

    def __init__(self, version, payload, account_sid, sid=None):
        """
        Initialize the FeedbackSummaryInstance

        :returns: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryInstance
        :rtype: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryInstance
        """
        super(FeedbackSummaryInstance, self).__init__(version)

        # Marshaled Properties
        self._properties = {
            'account_sid': payload.get('account_sid'),
            'call_count': deserialize.integer(payload.get('call_count')),
            'call_feedback_count': deserialize.integer(payload.get('call_feedback_count')),
            'date_created': deserialize.rfc2822_datetime(payload.get('date_created')),
            'date_updated': deserialize.rfc2822_datetime(payload.get('date_updated')),
            'end_date': deserialize.iso8601_date(payload.get('end_date')),
            'include_subaccounts': payload.get('include_subaccounts'),
            'issues': payload.get('issues'),
            'quality_score_average': deserialize.decimal(payload.get('quality_score_average')),
            'quality_score_median': deserialize.decimal(payload.get('quality_score_median')),
            'quality_score_standard_deviation': deserialize.decimal(payload.get('quality_score_standard_deviation')),
            'sid': payload.get('sid'),
            'start_date': deserialize.iso8601_date(payload.get('start_date')),
            'status': payload.get('status'),
        }

        # Context
        self._context = None
        self._solution = {'account_sid': account_sid, 'sid': sid or self._properties['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: FeedbackSummaryContext for this FeedbackSummaryInstance
        :rtype: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryContext
        """
        if self._context is None:
            self._context = FeedbackSummaryContext(
                self._version,
                account_sid=self._solution['account_sid'],
                sid=self._solution['sid'],
            )
        return self._context

    @property
    def account_sid(self):
        """
        :returns: The unique sid that identifies this account
        :rtype: unicode
        """
        return self._properties['account_sid']

    @property
    def call_count(self):
        """
        :returns: The total number of calls
        :rtype: unicode
        """
        return self._properties['call_count']

    @property
    def call_feedback_count(self):
        """
        :returns: The total number of calls with a feedback entry
        :rtype: unicode
        """
        return self._properties['call_feedback_count']

    @property
    def date_created(self):
        """
        :returns: The date this resource was created
        :rtype: datetime
        """
        return self._properties['date_created']

    @property
    def date_updated(self):
        """
        :returns: The date this resource was last updated
        :rtype: datetime
        """
        return self._properties['date_updated']

    @property
    def end_date(self):
        """
        :returns: The latest feedback entry date in the summary
        :rtype: date
        """
        return self._properties['end_date']

    @property
    def include_subaccounts(self):
        """
        :returns: Whether the feedback summary includes subaccounts
        :rtype: bool
        """
        return self._properties['include_subaccounts']

    @property
    def issues(self):
        """
        :returns: Issues experienced during the call
        :rtype: list[dict]
        """
        return self._properties['issues']

    @property
    def quality_score_average(self):
        """
        :returns: The average QualityScore of the feedback entries
        :rtype: unicode
        """
        return self._properties['quality_score_average']

    @property
    def quality_score_median(self):
        """
        :returns: The median QualityScore of the feedback entries
        :rtype: unicode
        """
        return self._properties['quality_score_median']

    @property
    def quality_score_standard_deviation(self):
        """
        :returns: The standard deviation of the quality scores
        :rtype: unicode
        """
        return self._properties['quality_score_standard_deviation']

    @property
    def sid(self):
        """
        :returns: A string that uniquely identifies this feedback entry
        :rtype: unicode
        """
        return self._properties['sid']

    @property
    def start_date(self):
        """
        :returns: The earliest feedback entry date in the summary
        :rtype: date
        """
        return self._properties['start_date']

    @property
    def status(self):
        """
        :returns: The status of the feedback summary
        :rtype: FeedbackSummaryInstance.Status
        """
        return self._properties['status']

    def fetch(self):
        """
        Fetch the FeedbackSummaryInstance

        :returns: The fetched FeedbackSummaryInstance
        :rtype: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryInstance
        """
        return self._proxy.fetch()

    def delete(self):
        """
        Deletes the FeedbackSummaryInstance

        :returns: True if delete succeeds, False otherwise
        :rtype: bool
        """
        return self._proxy.delete()

    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.Api.V2010.FeedbackSummaryInstance {}>'.format(context)
