package com.bocloud.ims.service.internal.worker;

import com.alibaba.fastjson.JSONArray;
import com.bocloud.common.model.Result;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * 目标机器或者HTTP请求的url或者DB的连接URL的执行结果信息封装类
 *
 * @author dmw
 */
public class HostResult extends Result {
    private Long id;
    private String host;// 这里可以表示远程目标机器，还可以表示远程服务的URL，或者数据库连接的URL
    private Double cost;
    private String rawName;
    private Integer port;
    private String user;
    private String task; // worker当前执行的任务名

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the host
     */
    public String getHost() {
        return host;
    }

    /**
     * @param host the host to set
     */
    public void setHost(String host) {
        this.host = host;
    }

    /**
     * @return the cost
     */
    public Double getCost() {
        return cost;
    }

    /**
     * @param cost the cost to set
     */
    public void setCost(Double cost) {
        this.cost = cost;
    }

    /**
     * @return the rawName
     */
    public String getRawName() {
        return rawName;
    }

    /**
     * @param rawName the rawName to set
     */
    public void setRawName(String rawName) {
        this.rawName = rawName;
    }

    /**
     * @return the port
     */
    public Integer getPort() {
        return port;
    }

    /**
     * @param port the port to set
     */
    public void setPort(Integer port) {
        this.port = port;
    }

    /**
     * @return the user
     */
    public String getUser() {
        return user;
    }

    /**
     *
     */
    public HostResult() {
        super();
    }

    /**
     * @param user the user to set
     */
    public void setUser(String user) {
        this.user = user;
    }

    public String getTask() {
        return task;
    }

    public void setTask(String task) {
        this.task = task;
    }

    /**
     * @param success
     * @param message
     */
    public HostResult(boolean success, String message) {
        super(success, message);
    }

    /**
     * @param success
     * @param message
     */
    public HostResult(boolean success, String message, String host) {
        super(success, message);
        this.host = host;
    }

    public HostResult(boolean success, String message, String host, String rawName, Integer port, String user) {
        super(success, message);
        this.host = host;
        this.rawName = rawName;
        this.port = port;
        this.user = user;
    }

    /**
     * @param host
     */
    public HostResult(String host) {
        this.host = host;
    }

    public static List<HostResult> convertList(String content) throws RuntimeException {
        if (StringUtils.isEmpty(content)) {
            throw new RuntimeException("参数为空！");
        }
        try {
            return JSONArray.parseArray(content, HostResult.class);
        } catch (Exception e) {
            throw new RuntimeException("目标主机任务结果参数异常", e);
        }
    }
}
