# -*- coding: utf-8 -*-
"""P2P 会话相关 API.

auto generated by script at 2017-08-24 21:50:13.459796. don't edit it.

"""
from typing import Any

from attr import NOTHING

from aiobearychat.abc import API
from aiobearychat.sansio import Response, clean_nothing_keys


class P2pAPI(API):
    """P2P 会话相关 API."""

    async def info(self,
                   p2p_channel_id: str,
                   **requester_params: Any) -> Response:
        """返回一个 P2P 聊天会话的完整信息。

        官方文档地址：https://github.com/bearyinnovative/OpenAPI/blob/master/api/p2p.info.md



        :param p2p_channel_id: P2P 聊天会话 id (示例: ``=bw52O``)
        :type p2p_channel_id: :class:`str`


        :return: response. 一个 :class:`aiobearychat.sansio.Response` 实例
        :rtype: :class:`aiobearychat.sansio.Response`

        ``response.body`` 返回值示例::

            response.status 等于 200 时:

                {
                  "id": "=bw52O",
                  "team_id": "=bw52O",
                  "vchannel_id": "=bw52O",
                  "type": "p2p",
                  "is_active": true,
                  "is_member": true,
                  "member_uids": [
                    "=bw52O",
                    "=bw52P"
                  ],
                  "latest_ts": 1485238998284
                }

        """
        url_params = {}
        body_params = {}
        url_params['token'] = self._token

        url_params.update({
            'p2p_channel_id': p2p_channel_id,
        })

        url = self.base_url + '/p2p.info'
        headers = {
            'content-type': 'application/json',
        }

        url_params = clean_nothing_keys(url_params)
        body_params = clean_nothing_keys(body_params)

        body_params = None

        return await self._make_request('get',
                                        url,
                                        url_params=url_params,
                                        body_params=body_params,
                                        headers=headers,
                                        **requester_params)

    async def list(self,
                   **requester_params: Any) -> Response:
        """返回 P2P 聊天会话列表，获取某个 P2P 会话的完整信息，请使用 ``p2p.info``.

        官方文档地址：https://github.com/bearyinnovative/OpenAPI/blob/master/api/p2p.list.md



        :return: response. 一个 :class:`aiobearychat.sansio.Response` 实例
        :rtype: :class:`aiobearychat.sansio.Response`

        ``response.body`` 返回值示例::

            response.status 等于 200 时:

                [
                  {
                    "id": "=bw52O",
                    "team_id": "=bw52O",
                    "vchannel_id": "=bw52O",
                    "type": "p2p",
                    "is_active": true,
                    "is_member": true,
                    "member_uids": [
                      "=bw52O",
                      "=bw52P"
                    ],
                    "latest_ts": 1485238998284
                  }
                ]

        """
        url_params = {}
        body_params = {}
        url_params['token'] = self._token

        url_params.update({
        })

        url = self.base_url + '/p2p.list'
        headers = {
            'content-type': 'application/json',
        }

        url_params = clean_nothing_keys(url_params)
        body_params = clean_nothing_keys(body_params)

        body_params = None

        return await self._make_request('get',
                                        url,
                                        url_params=url_params,
                                        body_params=body_params,
                                        headers=headers,
                                        **requester_params)

    async def create(self,
                     user_id: str,
                     **requester_params: Any) -> Response:
        """创建一个 P2P 聊天会话。

        官方文档地址：https://github.com/bearyinnovative/OpenAPI/blob/master/api/p2p.create.md



        :param user_id: P2P 聊天另外一方的用户 id (示例: ``=bw52O``)
        :type user_id: :class:`str`


        :return: response. 一个 :class:`aiobearychat.sansio.Response` 实例
        :rtype: :class:`aiobearychat.sansio.Response`

        ``response.body`` 返回值示例::

            response.status 等于 201 时:

                {
                  "id": "=bw52O",
                  "team_id": "=bw52O",
                  "vchannel_id": "=bw52O",
                  "type": "p2p",
                  "is_active": true,
                  "is_member": true,
                  "member_uids": [
                    "=bw52O",
                    "=bw52P"
                  ],
                  "latest_ts": 1485238998284
                }

        """
        url_params = {}
        body_params = {}
        body_params['token'] = self._token
        body_params.update({
            'user_id': user_id,
        })
        url = self.base_url + '/p2p.create'
        headers = {
            'content-type': 'application/json',
        }

        url_params = clean_nothing_keys(url_params)
        body_params = clean_nothing_keys(body_params)

        return await self._make_request('post',
                                        url,
                                        url_params=url_params,
                                        body_params=body_params,
                                        headers=headers,
                                        **requester_params)
