# -*- coding: utf-8 -*-
# 创建用户组
# 作者: 陈磊
# 时间: 2019-10-22
from WorkUtils.UtilsRequest import UtilsRequest
from WorkUtils.UtilsLog import UtilsLog


class UserGroupCreate(object):
    def __init__(self, _host, name=None, rights_permission=None, rights_id=None, tag_filters=None, userids=None):
        """
        :param _host: 域名
        :param name: 用户组名称
        :param rights_permission: 权限对象的等级
        :param rights_id: 权限对象的ID
        :param tag_filters: 标签
        :param userids: 需要添加的用户ID
        :return:
        """
        self.log = UtilsLog()
        self.log.info("调用创建用户组")
        self.log.info(self.__class__)

        self._host = _host
        self._headers = {}
        self._path = "/usergroup/create"
        self._url = self._host + self._path
        self._params = {}
        self._json = {}
        self.response = ""

        self.name = name
        self.rights_permission = rights_permission
        self.rights_id = rights_id
        self.tag_filters = tag_filters
        self.userids = userids

        self.api = UtilsRequest()

    def get_response(self):
        self._json = {
            "name": self.name,
            "rights": {
                "permissions": self.rights_permission,
                "id": self.rights_id
            },
            "tag_filters": self.tag_filters,
            "userids": self.userids,
        }
        self.response = self.api.post(url=self._url, json=self._json)
