# -*- coding: utf-8 -*-
# 创建媒体类型
# 作者: 陈磊
# 时间: 2019-11-08
from WorkUtils.UtilsRequest import UtilsRequest
from WorkUtils.UtilsLog import UtilsLog
from WorkApi.ApiBase import ApiBase, GetBase


class MediaTypeCreate(GetBase):
    def __init__(self, _host):
        """
        :param _host: 域名
        :return:
        """
        super().__init__()
        self.log = UtilsLog()
        self.log.info("调用创建媒体类型")
        self.log.info(self.__class__)

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

        self.local_json = {}

        self.description = None
        self.type = None
        self.exec_path = None
        self.gsm_modem = None
        self.passwd = None
        self.smtp_email = None
        self.smtp_helo = None
        self.smtp_server = None
        self.smtp_port = None
        self.smtp_security = None
        self.smtp_verify_host = None
        self.smtp_verify_peer = None
        self.smtp_authentication = None
        self.status = None
        self.username = None
        self.exec_params = None
        self.maxsessions = None
        self.maxattempts = None
        self.attempt_interval = None
        self.content_type = None

        self.api = UtilsRequest()

    def get_response(self):
        self.get_base_json()

        base = ApiBase()
        base.dict_add_key(_key="description", value=self.description)
        base.dict_add_key(_key="type", value=self.type)
        base.dict_add_key(_key="exec_path", value=self.exec_path)
        base.dict_add_key(_key="gsm_modem", value=self.gsm_modem)
        base.dict_add_key(_key="passwd", value=self.passwd)
        base.dict_add_key(_key="smtp_email", value=self.smtp_email)
        base.dict_add_key(_key="smtp_helo", value=self.smtp_helo)
        base.dict_add_key(_key="smtp_server", value=self.smtp_server)
        base.dict_add_key(_key="smtp_port", value=self.smtp_port)
        base.dict_add_key(_key="smtp_security", value=self.smtp_security)
        base.dict_add_key(_key="smtp_verify_host", value=self.smtp_verify_host)
        base.dict_add_key(_key="smtp_verify_peer", value=self.smtp_verify_peer)
        base.dict_add_key(_key="smtp_authentication", value=self.smtp_authentication)
        base.dict_add_key(_key="status", value=self.status)
        base.dict_add_key(_key="username", value=self.username)
        base.dict_add_key(_key="exec_params", value=self.exec_params)
        base.dict_add_key(_key="maxsessions", value=self.maxsessions)
        base.dict_add_key(_key="maxattempts", value=self.maxattempts)
        base.dict_add_key(_key="attempt_interval", value=self.attempt_interval)
        base.dict_add_key(_key="content_type", value=self.content_type)

        self.local_json = base._json

        # self.log.debug(self.local_json)
        # self.log.debug(self.base_json)

        # 当前接口支持的参数与公共参数合并
        add = ApiBase()
        add.dict_add_dict(_dict_1=self.local_json, _dict_2=self.base_json)
        self._json = add._json
        self.response = self.api.post(url=self._url, json=self._json)
