r"""
    This code was generated by
   ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
    |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
    |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \

    Twilio - Video
    This is the public Twilio REST API.

    NOTE: This class is auto generated by OpenAPI Generator.
    https://openapi-generator.tech
    Do not edit the class manually.
"""

from datetime import datetime
from typing import Any, Dict, List, Optional, Union
from twilio.base import deserialize, serialize, values
from twilio.base.api_response import ApiResponse

from twilio.base.instance_resource import InstanceResource
from twilio.base.list_resource import ListResource
from twilio.base.version import Version


class RecordingRulesInstance(InstanceResource):
    """
    :ivar room_sid: The SID of the Room resource for the Recording Rules
    :ivar rules: A collection of Recording Rules that describe how to include or exclude matching tracks for recording
    :ivar date_created: The date and time in GMT when the resource was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
    :ivar date_updated: The date and time in GMT when the resource was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
    """

    def __init__(self, version: Version, payload: Dict[str, Any], room_sid: str):
        super().__init__(version)

        self.room_sid: Optional[str] = payload.get("room_sid")
        self.rules: Optional[List[str]] = payload.get("rules")
        self.date_created: Optional[datetime] = deserialize.iso8601_datetime(
            payload.get("date_created")
        )
        self.date_updated: Optional[datetime] = deserialize.iso8601_datetime(
            payload.get("date_updated")
        )

        self._solution = {
            "room_sid": room_sid,
        }

    def __repr__(self) -> str:
        """
        Provide a friendly representation

        :returns: Machine friendly representation
        """
        context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
        return "<Twilio.Video.V1.RecordingRulesInstance {}>".format(context)


class RecordingRulesList(ListResource):

    def __init__(self, version: Version, room_sid: str):
        """
        Initialize the RecordingRulesList

        :param version: Version that contains the resource
        :param room_sid: The SID of the Room resource where the recording rules to update apply.

        """
        super().__init__(version)

        # Path Solution
        self._solution = {
            "room_sid": room_sid,
        }
        self._uri = "/Rooms/{room_sid}/RecordingRules".format(**self._solution)

    def _fetch(self) -> tuple:
        """
        Internal helper for fetch operation

        Returns:
            tuple: (payload, status_code, headers)
        """
        headers = values.of({"Content-Type": "application/x-www-form-urlencoded"})

        headers["Accept"] = "application/json"

        return self._version.fetch_with_response_info(
            method="GET", uri=self._uri, headers=headers
        )

    def fetch(self) -> RecordingRulesInstance:
        """
        Fetch the RecordingRulesInstance


        :returns: The fetched RecordingRulesInstance
        """
        payload, _, _ = self._fetch()
        return RecordingRulesInstance(
            self._version, payload, room_sid=self._solution["room_sid"]
        )

    def fetch_with_http_info(self) -> ApiResponse:
        """
        Fetch the RecordingRulesInstance and return response metadata


        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = self._fetch()
        instance = RecordingRulesInstance(
            self._version, payload, room_sid=self._solution["room_sid"]
        )
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

    async def _fetch_async(self) -> tuple:
        """
        Internal async helper for fetch operation

        Returns:
            tuple: (payload, status_code, headers)
        """
        headers = values.of({"Content-Type": "application/x-www-form-urlencoded"})

        headers["Accept"] = "application/json"

        return await self._version.fetch_with_response_info_async(
            method="GET", uri=self._uri, headers=headers
        )

    async def fetch_async(self) -> RecordingRulesInstance:
        """
        Asynchronously fetch the RecordingRulesInstance


        :returns: The fetched RecordingRulesInstance
        """
        payload, _, _ = await self._fetch_async()
        return RecordingRulesInstance(
            self._version, payload, room_sid=self._solution["room_sid"]
        )

    async def fetch_with_http_info_async(self) -> ApiResponse:
        """
        Asynchronously fetch the RecordingRulesInstance and return response metadata


        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = await self._fetch_async()
        instance = RecordingRulesInstance(
            self._version, payload, room_sid=self._solution["room_sid"]
        )
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

    def _update(self, rules: Union[object, object] = values.unset) -> tuple:
        """
        Internal helper for update operation

        Returns:
            tuple: (payload, status_code, headers)
        """

        data = values.of(
            {
                "Rules": serialize.object(rules),
            }
        )
        headers = values.of({"Content-Type": "application/x-www-form-urlencoded"})

        headers["Content-Type"] = "application/x-www-form-urlencoded"

        headers["Accept"] = "application/json"

        return self._version.update_with_response_info(
            method="POST", uri=self._uri, data=data, headers=headers
        )

    def update(
        self, rules: Union[object, object] = values.unset
    ) -> RecordingRulesInstance:
        """
        Update the RecordingRulesInstance

        :param rules: A JSON-encoded array of recording rules.

        :returns: The updated RecordingRulesInstance
        """
        payload, _, _ = self._update(rules=rules)
        return RecordingRulesInstance(
            self._version, payload, room_sid=self._solution["room_sid"]
        )

    def update_with_http_info(
        self, rules: Union[object, object] = values.unset
    ) -> ApiResponse:
        """
        Update the RecordingRulesInstance and return response metadata

        :param rules: A JSON-encoded array of recording rules.

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = self._update(rules=rules)
        instance = RecordingRulesInstance(
            self._version, payload, room_sid=self._solution["room_sid"]
        )
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

    async def _update_async(self, rules: Union[object, object] = values.unset) -> tuple:
        """
        Internal async helper for update operation

        Returns:
            tuple: (payload, status_code, headers)
        """

        data = values.of(
            {
                "Rules": serialize.object(rules),
            }
        )
        headers = values.of({"Content-Type": "application/x-www-form-urlencoded"})

        headers["Content-Type"] = "application/x-www-form-urlencoded"

        headers["Accept"] = "application/json"

        return await self._version.update_with_response_info_async(
            method="POST", uri=self._uri, data=data, headers=headers
        )

    async def update_async(
        self, rules: Union[object, object] = values.unset
    ) -> RecordingRulesInstance:
        """
        Asynchronously update the RecordingRulesInstance

        :param rules: A JSON-encoded array of recording rules.

        :returns: The updated RecordingRulesInstance
        """
        payload, _, _ = await self._update_async(rules=rules)
        return RecordingRulesInstance(
            self._version, payload, room_sid=self._solution["room_sid"]
        )

    async def update_with_http_info_async(
        self, rules: Union[object, object] = values.unset
    ) -> ApiResponse:
        """
        Asynchronously update the RecordingRulesInstance and return response metadata

        :param rules: A JSON-encoded array of recording rules.

        :returns: ApiResponse with instance, status code, and headers
        """
        payload, status_code, headers = await self._update_async(rules=rules)
        instance = RecordingRulesInstance(
            self._version, payload, room_sid=self._solution["room_sid"]
        )
        return ApiResponse(data=instance, status_code=status_code, headers=headers)

    def __repr__(self) -> str:
        """
        Provide a friendly representation

        :returns: Machine friendly representation
        """
        return "<Twilio.Video.V1.RecordingRulesList>"
