# 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
from twilio.rest.api.v2010.account.conference.participant import ParticipantList
from twilio.rest.api.v2010.account.conference.recording import RecordingList


class ConferenceList(ListResource):
    """  """

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

        :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.conference.ConferenceList
        :rtype: twilio.rest.api.v2010.account.conference.ConferenceList
        """
        super(ConferenceList, self).__init__(version)

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

    def stream(self, date_created_before=values.unset, date_created=values.unset,
               date_created_after=values.unset, date_updated_before=values.unset,
               date_updated=values.unset, date_updated_after=values.unset,
               friendly_name=values.unset, status=values.unset, limit=None,
               page_size=None):
        """
        Streams ConferenceInstance records from the API as a generator stream.
        This operation lazily loads records as efficiently as possible until the limit
        is reached.
        The results are returned as a generator, so this operation is memory efficient.

        :param date date_created_before: The `YYYY-MM-DD` value of the resources to read
        :param date date_created: The `YYYY-MM-DD` value of the resources to read
        :param date date_created_after: The `YYYY-MM-DD` value of the resources to read
        :param date date_updated_before: The `YYYY-MM-DD` value of the resources to read
        :param date date_updated: The `YYYY-MM-DD` value of the resources to read
        :param date date_updated_after: The `YYYY-MM-DD` value of the resources to read
        :param unicode friendly_name: The string that identifies the Conference resources to read
        :param ConferenceInstance.Status status: The status of the resources to read
        :param int limit: Upper limit for the number of records to return. stream()
                          guarantees to never return more than limit.  Default is no limit
        :param int page_size: Number of records to fetch per request, when not set will use
                              the default value of 50 records.  If no page_size is defined
                              but a limit is defined, stream() will attempt to read the
                              limit with the most efficient page size, i.e. min(limit, 1000)

        :returns: Generator that will yield up to limit results
        :rtype: list[twilio.rest.api.v2010.account.conference.ConferenceInstance]
        """
        limits = self._version.read_limits(limit, page_size)

        page = self.page(
            date_created_before=date_created_before,
            date_created=date_created,
            date_created_after=date_created_after,
            date_updated_before=date_updated_before,
            date_updated=date_updated,
            date_updated_after=date_updated_after,
            friendly_name=friendly_name,
            status=status,
            page_size=limits['page_size'],
        )

        return self._version.stream(page, limits['limit'])

    def list(self, date_created_before=values.unset, date_created=values.unset,
             date_created_after=values.unset, date_updated_before=values.unset,
             date_updated=values.unset, date_updated_after=values.unset,
             friendly_name=values.unset, status=values.unset, limit=None,
             page_size=None):
        """
        Lists ConferenceInstance records from the API as a list.
        Unlike stream(), this operation is eager and will load `limit` records into
        memory before returning.

        :param date date_created_before: The `YYYY-MM-DD` value of the resources to read
        :param date date_created: The `YYYY-MM-DD` value of the resources to read
        :param date date_created_after: The `YYYY-MM-DD` value of the resources to read
        :param date date_updated_before: The `YYYY-MM-DD` value of the resources to read
        :param date date_updated: The `YYYY-MM-DD` value of the resources to read
        :param date date_updated_after: The `YYYY-MM-DD` value of the resources to read
        :param unicode friendly_name: The string that identifies the Conference resources to read
        :param ConferenceInstance.Status status: The status of the resources to read
        :param int limit: Upper limit for the number of records to return. list() guarantees
                          never to return more than limit.  Default is no limit
        :param int page_size: Number of records to fetch per request, when not set will use
                              the default value of 50 records.  If no page_size is defined
                              but a limit is defined, list() will attempt to read the limit
                              with the most efficient page size, i.e. min(limit, 1000)

        :returns: Generator that will yield up to limit results
        :rtype: list[twilio.rest.api.v2010.account.conference.ConferenceInstance]
        """
        return list(self.stream(
            date_created_before=date_created_before,
            date_created=date_created,
            date_created_after=date_created_after,
            date_updated_before=date_updated_before,
            date_updated=date_updated,
            date_updated_after=date_updated_after,
            friendly_name=friendly_name,
            status=status,
            limit=limit,
            page_size=page_size,
        ))

    def page(self, date_created_before=values.unset, date_created=values.unset,
             date_created_after=values.unset, date_updated_before=values.unset,
             date_updated=values.unset, date_updated_after=values.unset,
             friendly_name=values.unset, status=values.unset,
             page_token=values.unset, page_number=values.unset,
             page_size=values.unset):
        """
        Retrieve a single page of ConferenceInstance records from the API.
        Request is executed immediately

        :param date date_created_before: The `YYYY-MM-DD` value of the resources to read
        :param date date_created: The `YYYY-MM-DD` value of the resources to read
        :param date date_created_after: The `YYYY-MM-DD` value of the resources to read
        :param date date_updated_before: The `YYYY-MM-DD` value of the resources to read
        :param date date_updated: The `YYYY-MM-DD` value of the resources to read
        :param date date_updated_after: The `YYYY-MM-DD` value of the resources to read
        :param unicode friendly_name: The string that identifies the Conference resources to read
        :param ConferenceInstance.Status status: The status of the resources to read
        :param str page_token: PageToken provided by the API
        :param int page_number: Page Number, this value is simply for client state
        :param int page_size: Number of records to return, defaults to 50

        :returns: Page of ConferenceInstance
        :rtype: twilio.rest.api.v2010.account.conference.ConferencePage
        """
        data = values.of({
            'DateCreated<': serialize.iso8601_date(date_created_before),
            'DateCreated': serialize.iso8601_date(date_created),
            'DateCreated>': serialize.iso8601_date(date_created_after),
            'DateUpdated<': serialize.iso8601_date(date_updated_before),
            'DateUpdated': serialize.iso8601_date(date_updated),
            'DateUpdated>': serialize.iso8601_date(date_updated_after),
            'FriendlyName': friendly_name,
            'Status': status,
            'PageToken': page_token,
            'Page': page_number,
            'PageSize': page_size,
        })

        response = self._version.page(method='GET', uri=self._uri, params=data, )

        return ConferencePage(self._version, response, self._solution)

    def get_page(self, target_url):
        """
        Retrieve a specific page of ConferenceInstance records from the API.
        Request is executed immediately

        :param str target_url: API-generated URL for the requested results page

        :returns: Page of ConferenceInstance
        :rtype: twilio.rest.api.v2010.account.conference.ConferencePage
        """
        response = self._version.domain.twilio.request(
            'GET',
            target_url,
        )

        return ConferencePage(self._version, response, self._solution)

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

        :param sid: The unique string that identifies this resource

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

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

        :param sid: The unique string that identifies this resource

        :returns: twilio.rest.api.v2010.account.conference.ConferenceContext
        :rtype: twilio.rest.api.v2010.account.conference.ConferenceContext
        """
        return ConferenceContext(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.ConferenceList>'


class ConferencePage(Page):
    """  """

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

        :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.conference.ConferencePage
        :rtype: twilio.rest.api.v2010.account.conference.ConferencePage
        """
        super(ConferencePage, self).__init__(version, response)

        # Path Solution
        self._solution = solution

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

        :param dict payload: Payload response from the API

        :returns: twilio.rest.api.v2010.account.conference.ConferenceInstance
        :rtype: twilio.rest.api.v2010.account.conference.ConferenceInstance
        """
        return ConferenceInstance(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.ConferencePage>'


class ConferenceContext(InstanceContext):
    """  """

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

        :param Version version: Version that contains the resource
        :param account_sid: The SID of the Account that created the resource(s) to fetch
        :param sid: The unique string that identifies this resource

        :returns: twilio.rest.api.v2010.account.conference.ConferenceContext
        :rtype: twilio.rest.api.v2010.account.conference.ConferenceContext
        """
        super(ConferenceContext, self).__init__(version)

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

        # Dependents
        self._participants = None
        self._recordings = None

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

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

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

    def update(self, status=values.unset, announce_url=values.unset,
               announce_method=values.unset):
        """
        Update the ConferenceInstance

        :param ConferenceInstance.UpdateStatus status: The new status of the resource
        :param unicode announce_url: The URL we should call to announce something into the conference
        :param unicode announce_method: he HTTP method used to call announce_url

        :returns: The updated ConferenceInstance
        :rtype: twilio.rest.api.v2010.account.conference.ConferenceInstance
        """
        data = values.of({'Status': status, 'AnnounceUrl': announce_url, 'AnnounceMethod': announce_method, })

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

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

    @property
    def participants(self):
        """
        Access the participants

        :returns: twilio.rest.api.v2010.account.conference.participant.ParticipantList
        :rtype: twilio.rest.api.v2010.account.conference.participant.ParticipantList
        """
        if self._participants is None:
            self._participants = ParticipantList(
                self._version,
                account_sid=self._solution['account_sid'],
                conference_sid=self._solution['sid'],
            )
        return self._participants

    @property
    def recordings(self):
        """
        Access the recordings

        :returns: twilio.rest.api.v2010.account.conference.recording.RecordingList
        :rtype: twilio.rest.api.v2010.account.conference.recording.RecordingList
        """
        if self._recordings is None:
            self._recordings = RecordingList(
                self._version,
                account_sid=self._solution['account_sid'],
                conference_sid=self._solution['sid'],
            )
        return self._recordings

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


class ConferenceInstance(InstanceResource):
    """  """

    class Status(object):
        INIT = "init"
        IN_PROGRESS = "in-progress"
        COMPLETED = "completed"

    class UpdateStatus(object):
        COMPLETED = "completed"

    class ReasonConferenceEnded(object):
        CONFERENCE_ENDED_VIA_API = "conference-ended-via-api"
        PARTICIPANT_WITH_END_CONFERENCE_ON_EXIT_LEFT = "participant-with-end-conference-on-exit-left"
        PARTICIPANT_WITH_END_CONFERENCE_ON_EXIT_KICKED = "participant-with-end-conference-on-exit-kicked"
        LAST_PARTICIPANT_KICKED = "last-participant-kicked"
        LAST_PARTICIPANT_LEFT = "last-participant-left"

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

        :returns: twilio.rest.api.v2010.account.conference.ConferenceInstance
        :rtype: twilio.rest.api.v2010.account.conference.ConferenceInstance
        """
        super(ConferenceInstance, self).__init__(version)

        # Marshaled Properties
        self._properties = {
            'account_sid': payload.get('account_sid'),
            'date_created': deserialize.rfc2822_datetime(payload.get('date_created')),
            'date_updated': deserialize.rfc2822_datetime(payload.get('date_updated')),
            'api_version': payload.get('api_version'),
            'friendly_name': payload.get('friendly_name'),
            'region': payload.get('region'),
            'sid': payload.get('sid'),
            'status': payload.get('status'),
            'uri': payload.get('uri'),
            'subresource_uris': payload.get('subresource_uris'),
            'reason_conference_ended': payload.get('reason_conference_ended'),
            'call_sid_ending_conference': payload.get('call_sid_ending_conference'),
        }

        # 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: ConferenceContext for this ConferenceInstance
        :rtype: twilio.rest.api.v2010.account.conference.ConferenceContext
        """
        if self._context is None:
            self._context = ConferenceContext(
                self._version,
                account_sid=self._solution['account_sid'],
                sid=self._solution['sid'],
            )
        return self._context

    @property
    def account_sid(self):
        """
        :returns: The SID of the Account that created this resource
        :rtype: unicode
        """
        return self._properties['account_sid']

    @property
    def date_created(self):
        """
        :returns: The RFC 2822 date and time in GMT that this resource was created
        :rtype: datetime
        """
        return self._properties['date_created']

    @property
    def date_updated(self):
        """
        :returns: The RFC 2822 date and time in GMT that this resource was last updated
        :rtype: datetime
        """
        return self._properties['date_updated']

    @property
    def api_version(self):
        """
        :returns: The API version used to create this conference
        :rtype: unicode
        """
        return self._properties['api_version']

    @property
    def friendly_name(self):
        """
        :returns: A string that you assigned to describe this conference room
        :rtype: unicode
        """
        return self._properties['friendly_name']

    @property
    def region(self):
        """
        :returns: A string that represents the Twilio Region where the conference was mixed
        :rtype: unicode
        """
        return self._properties['region']

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

    @property
    def status(self):
        """
        :returns: The status of this conference
        :rtype: ConferenceInstance.Status
        """
        return self._properties['status']

    @property
    def uri(self):
        """
        :returns: The URI of this resource, relative to `https://api.twilio.com`
        :rtype: unicode
        """
        return self._properties['uri']

    @property
    def subresource_uris(self):
        """
        :returns: A list of related resources identified by their relative URIs
        :rtype: unicode
        """
        return self._properties['subresource_uris']

    @property
    def reason_conference_ended(self):
        """
        :returns: The reason why a conference ended.
        :rtype: ConferenceInstance.ReasonConferenceEnded
        """
        return self._properties['reason_conference_ended']

    @property
    def call_sid_ending_conference(self):
        """
        :returns: The call SID that caused the conference to end
        :rtype: unicode
        """
        return self._properties['call_sid_ending_conference']

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

        :returns: The fetched ConferenceInstance
        :rtype: twilio.rest.api.v2010.account.conference.ConferenceInstance
        """
        return self._proxy.fetch()

    def update(self, status=values.unset, announce_url=values.unset,
               announce_method=values.unset):
        """
        Update the ConferenceInstance

        :param ConferenceInstance.UpdateStatus status: The new status of the resource
        :param unicode announce_url: The URL we should call to announce something into the conference
        :param unicode announce_method: he HTTP method used to call announce_url

        :returns: The updated ConferenceInstance
        :rtype: twilio.rest.api.v2010.account.conference.ConferenceInstance
        """
        return self._proxy.update(status=status, announce_url=announce_url, announce_method=announce_method, )

    @property
    def participants(self):
        """
        Access the participants

        :returns: twilio.rest.api.v2010.account.conference.participant.ParticipantList
        :rtype: twilio.rest.api.v2010.account.conference.participant.ParticipantList
        """
        return self._proxy.participants

    @property
    def recordings(self):
        """
        Access the recordings

        :returns: twilio.rest.api.v2010.account.conference.recording.RecordingList
        :rtype: twilio.rest.api.v2010.account.conference.recording.RecordingList
        """
        return self._proxy.recordings

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