package cn.reghao.bnt.web.devops.app.model.po.config;

import cn.reghao.bnt.web.devops.machine.model.po.MachineHost;
import cn.reghao.bnt.web.util.BaseEntity;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

/**
 * 应用部署配置
 *
 * @author reghao
 * @date 2020-05-13 16:59:20
 */
@NoArgsConstructor
@Getter
@Setter
@Entity
@Table(name = "devops_app_deploy_config")
public class AppDeployConfig extends BaseEntity {
    @NotNull
    @OneToOne
    private AppConfig appConfig;
    @NotNull
    @OneToOne
    private MachineHost machineHost;
    // packType 是 docker 时 startScript 的内容是 cn.reghao.bnt.common.docker.model.Config 序列化为 JSON 后的字符串
    // 具体参照 https://docs.docker.com/engine/api/v1.40/#operation/ContainerCreate 的 reqeust body
    @Column(columnDefinition="text")
    @NotNull
    @NotBlank(message = "startScript 不能为空白字符串")
    private String startScript;
    @Column(columnDefinition="text")
    private String unpackScript;
    private String startHome;

    public AppDeployConfig(AppConfig appConfig, MachineHost machineHost, String startScript) {
        this.appConfig = appConfig;
        this.machineHost = machineHost;
        this.startScript = startScript;
    }
}
