# -*- coding: utf-8 -*-
# 查询趋势
# 作者: 陈磊
# 时间: 2019-10-24
from WorkUtils.UtilsRequest import UtilsRequest
from WorkUtils.UtilsLog import UtilsLog


class TrendGet(object):
    def __init__(self, _host, time_from=None, time_till=None, limit=None):
        """
        :param _host: 域名
        :param time_from: 应用ID
        :param time_till : 主机组的ID
        :param limit: 应用名称
        :return:
        """
        self.log = UtilsLog()
        self.log.info("调用查询趋势接口")
        self.log.info(self.__class__)

        self._host = _host
        self._headers = {}
        self._path = "/trend/get"
        self._url = self._host + self._path
        self._params = {}
        self._json = {}
        self.response = ""

        self.time_from = time_from
        self.time_till = time_till
        self.limit = limit
        self.output = []
        self.itemids = []
        self.countOutput = []

        self.api = UtilsRequest()

    def output_add(self, output):
        """
        :param output:
        :return:
        """
        self.output.append(output)

    def itemids_add(self, itemid):
        """
        :param itemid:
        :return:
        """
        self.itemids.append(itemid)

    def get_response(self):
        self._json = {
            "time_from": self.time_from,
            "time_till": self.time_till,
            "limit": self.limit,
            "output": self.output,
            "itemids": self.itemids,
        }
        self.response = self.api.post(url=self._url, json=self._json)
