package cn.reghao.bnt.web.devops.app.model.vo;

import cn.reghao.jutil.jdk.web.result.NotAvailable;
import cn.reghao.bnt.web.devops.app.model.po.AppDeployingNode;
import cn.reghao.bnt.web.devops.app.model.po.log.BuildLog;
import cn.reghao.bnt.web.devops.machine.model.po.MachineHost;
import cn.reghao.jutil.jdk.converter.DateTimeConverter;
import lombok.Data;

/**
 * @author reghao
 * @date 2021-05-21 09:57:35
 */
@Data
public class AppDeployingNodeVO {
    private String machineId;
    private String machineIpv4;
    private String machineStatus;
    private String commitId;
    private String packagePath;
    private String deployBy;
    private String deployTime;
    private String deployResult;

    public AppDeployingNodeVO(AppDeployingNode deployingNode, BuildLog buildLog, String machineStatus) {
        MachineHost machineHost = deployingNode.getDeployConfig().getMachineHost();
        this.machineId = machineHost.getMachineId();
        this.machineIpv4 = machineHost.getMachineIpv4();
        this.machineStatus = machineStatus;

        if (buildLog != null) {
            this.commitId = buildLog.getCommitId() != null ? buildLog.getCommitId() : NotAvailable.na.getDesc();
            this.packagePath = buildLog.getPackagePath() != null ? buildLog.getPackagePath() : NotAvailable.na.getDesc();
        } else {
            this.commitId = NotAvailable.na.getDesc();
            this.packagePath = NotAvailable.na.getDesc();
        }

        this.deployBy = deployingNode.getDeployBy() != null ?
                deployingNode.getDeployBy() : NotAvailable.na.getDesc();
        this.deployTime = deployingNode.getDeployTime() != null ?
                DateTimeConverter.format(deployingNode.getDeployTime()) : NotAvailable.na.getDesc();
        this.deployResult = deployingNode.getDeployResult();
    }
}
