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

from twilio import deserialize
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
from twilio.rest.conversations.v1.conversation.completed import CompletedList
from twilio.rest.conversations.v1.conversation.in_progress import InProgressList
from twilio.rest.conversations.v1.conversation.participant import ParticipantList


class ConversationList(ListResource):

    def __init__(self, version):
        """
        Initialize the ConversationList
        
        :param Version version: Version that contains the resource
        
        :returns: ConversationList
        :rtype: ConversationList
        """
        super(ConversationList, self).__init__(version)
        
        # Path Solution
        self._solution = {}
        
        # Components
        self._in_progress = None
        self._completed = None

    @property
    def in_progress(self):
        """
        Access the in_progress
        
        :returns: InProgressList
        :rtype: InProgressList
        """
        if self._in_progress is None:
            self._in_progress = InProgressList(
                self._version,
            )
        return self._in_progress

    @property
    def completed(self):
        """
        Access the completed
        
        :returns: CompletedList
        :rtype: CompletedList
        """
        if self._completed is None:
            self._completed = CompletedList(
                self._version,
            )
        return self._completed

    def get(self, sid):
        """
        Constructs a ConversationContext
        
        :param sid: The sid
        
        :returns: ConversationContext
        :rtype: ConversationContext
        """
        return ConversationContext(
            self._version,
            sid=sid,
        )

    def __call__(self, sid):
        """
        Constructs a ConversationContext
        
        :param sid: The sid
        
        :returns: ConversationContext
        :rtype: ConversationContext
        """
        return ConversationContext(
            self._version,
            sid=sid,
        )

    def __repr__(self):
        """
        Provide a friendly representation
        
        :returns: Machine friendly representation
        :rtype: str
        """
        return '<Twilio.Conversations.V1.ConversationList>'


class ConversationPage(Page):

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

    def get_instance(self, payload):
        """
        Build an instance of ConversationInstance
        
        :param dict payload: Payload response from the API
        
        :returns: ConversationInstance
        :rtype: ConversationInstance
        """
        return ConversationInstance(
            self._version,
            payload,
        )

    def __repr__(self):
        """
        Provide a friendly representation
        
        :returns: Machine friendly representation
        :rtype: str
        """
        return '<Twilio.Conversations.V1.ConversationPage>'


class ConversationContext(InstanceContext):

    def __init__(self, version, sid):
        """
        Initialize the ConversationContext
        
        :param Version version: Version that contains the resource
        :param sid: The sid
        
        :returns: ConversationContext
        :rtype: ConversationContext
        """
        super(ConversationContext, self).__init__(version)
        
        # Path Solution
        self._solution = {
            'sid': sid,
        }
        self._uri = '/Conversations/{sid}'.format(**self._solution)
        
        # Dependents
        self._participants = None

    def fetch(self):
        """
        Fetch a ConversationInstance
        
        :returns: Fetched ConversationInstance
        :rtype: ConversationInstance
        """
        params = values.of({})
        
        payload = self._version.fetch(
            'GET',
            self._uri,
            params=params,
        )
        
        return ConversationInstance(
            self._version,
            payload,
            sid=self._solution['sid'],
        )

    @property
    def participants(self):
        """
        Access the participants
        
        :returns: ParticipantList
        :rtype: ParticipantList
        """
        if self._participants is None:
            self._participants = ParticipantList(
                self._version,
                conversation_sid=self._solution['sid'],
            )
        return self._participants

    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.Conversations.V1.ConversationContext {}>'.format(context)


class ConversationInstance(InstanceResource):

    def __init__(self, version, payload, sid=None):
        """
        Initialize the ConversationInstance
        
        :returns: ConversationInstance
        :rtype: ConversationInstance
        """
        super(ConversationInstance, self).__init__(version)
        
        # Marshaled Properties
        self._properties = {
            'sid': payload['sid'],
            'status': payload['status'],
            'duration': deserialize.integer(payload['duration']),
            'date_created': deserialize.iso8601_datetime(payload['date_created']),
            'start_time': deserialize.iso8601_datetime(payload['start_time']),
            'end_time': deserialize.iso8601_datetime(payload['end_time']),
            'account_sid': payload['account_sid'],
            'url': payload['url'],
        }
        
        # Context
        self._context = None
        self._solution = {
            '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: ConversationContext for this ConversationInstance
        :rtype: ConversationContext
        """
        if self._context is None:
            self._context = ConversationContext(
                self._version,
                sid=self._solution['sid'],
            )
        return self._context

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

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

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

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

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

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

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

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

    def fetch(self):
        """
        Fetch a ConversationInstance
        
        :returns: Fetched ConversationInstance
        :rtype: ConversationInstance
        """
        return self._proxy.fetch()

    @property
    def participants(self):
        """
        Access the participants
        
        :returns: participants
        :rtype: participants
        """
        return self._proxy.participants

    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.Conversations.V1.ConversationInstance {}>'.format(context)
