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.AppBuilding;
import cn.reghao.bnt.web.devops.app.model.po.config.AppConfig;
import cn.reghao.jutil.jdk.converter.DateTimeConverter;
import lombok.Data;

/**
 * @author reghao
 * @date 2021-05-21 09:57:35
 */
@Data
public class AppBuildingVO {
    private String appId;
    private String appName;
    private String appType;
    private String env;
    private String repoBranch;
    private String bindPorts;

    private String buildLogId;
    private String commitId;
    private String commitTime;
    private String buildTime;
    private String buildResult;
    private String packagePath;
    private String buildBy;
    private int totalNode;
    private int totalRunning;

    public AppBuildingVO(AppBuilding appBuilding, int totalNode, int totalRunning) {
        AppConfig appConfig = appBuilding.getAppConfig();
        this.appId = appConfig.getAppId();
        this.appName = appConfig.getAppName();
        this.appType = appConfig.getAppType();
        this.env = appConfig.getEnv();
        this.repoBranch = appConfig.getRepoBranch();
        this.bindPorts = appConfig.getBindPorts();

        this.buildLogId = appBuilding.getBuildLog() == null ? NotAvailable.na.getDesc() : appBuilding.getBuildLog().getBuildLogId();
        this.commitId = appBuilding.getCommitId() == null ? NotAvailable.na.getDesc() : appBuilding.getCommitId();
        this.commitTime = appBuilding.getCommitTime() == null ? NotAvailable.na.getDesc() : DateTimeConverter.format(appBuilding.getCommitTime());
        this.buildTime = appBuilding.getBuildTime() == null ? NotAvailable.na.getDesc() : DateTimeConverter.format(appBuilding.getBuildTime());
        this.buildResult = appBuilding.getBuildResult();
        this.packagePath = appBuilding.getPackagePath() == null ? NotAvailable.na.getDesc() : appBuilding.getPackagePath();
        this.buildBy = appBuilding.getBuildBy() == null ? NotAvailable.na.getDesc() : appBuilding.getBuildBy();
        this.totalNode = totalNode;
        this.totalRunning = totalRunning;
    }
}
