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


class TaskCreate(object):
    def __init__(self, _host, _type=None):
        """
        :param _host: 域名
        :param _type: 任务类型
        :return:
        """
        self.log = UtilsLog()
        self.log.info("调用创建任务")
        self.log.info(self.__class__)

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

        self.itemids = []
        self._type = _type

        self.api = UtilsRequest()

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

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