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

import cn.reghao.bnt.web.devops.app.model.po.config.AppConfig;
import cn.reghao.bnt.web.devops.app.model.po.config.AppDeployConfig;
import cn.reghao.bnt.web.devops.app.model.po.log.BuildLog;
import cn.reghao.bnt.web.util.BaseEntity;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import java.util.List;

/**
 * 应用最新一次构建的部署状态
 *
 * @author reghao
 * @date 2021-05-21 09:57:35
 */
@NoArgsConstructor
@Getter
@Setter
@Entity
@Table(name = "devops_app_deploying")
public class AppDeploying extends BaseEntity {
    @OneToOne
    private AppConfig appConfig;
    @OneToOne
    private BuildLog buildLog;

    @NotNull
    @ElementCollection(targetClass = AppDeployingNode.class)
    @LazyCollection(LazyCollectionOption.FALSE)
    @CollectionTable(name = "devops_app_deploying_nodes")
    private List<AppDeployingNode> deployingNodes;

    public AppDeploying(AppDeployConfig appDeployConfig) {
        this.appConfig = appDeployConfig.getAppConfig();
        this.deployingNodes = List.of(new AppDeployingNode(appDeployConfig));
    }
}
