package cn.reghao.autodop.dmaster.app.model.po;

import cn.reghao.autodop.common.msg.rpc.dto.app.DeployResult;
import cn.reghao.autodop.dmaster.app.model.po.config.AppConfig;
import cn.reghao.autodop.dmaster.app.model.po.config.DeployConfig;
import cn.reghao.autodop.dmaster.app.model.po.log.BuildLog;
import lombok.*;

import javax.persistence.Entity;
import java.time.LocalDateTime;

/**
 * 需要部署的应用
 *
 * @author reghao
 * @date 2021-05-21 09:57:35
 */
@NoArgsConstructor
@Getter
@Setter
@Entity
public class AppDeploying extends AppProperty {
    private String buildLogId;
    private String commitId;
    private String packagePath;
    private LocalDateTime deployTime;
    private String deployResult;
    private String deployBy;

    public AppDeploying(AppConfig app, DeployConfig deployConfig) {
        super(app, deployConfig);
    }

    public AppDeploying refresh(String appName, String machineIpv4) {
        this.update0(appName, machineIpv4);
        return this;
    }

    public AppDeploying update(BuildLog buildLog, DeployResult deployResult) {
        this.setBuildLogId(buildLog.getId());
        this.setCommitId(buildLog.getCommitInfo().getCommitId());
        this.setPackagePath(buildLog.getPackagePath());
        this.setDeployTime(deployResult.getDeployTime());
        this.setDeployResult(deployResult.getResult().getMsg());
        this.setDeployBy("某人");
        return this;
    }
}
