package com.lanyuanxiaoyao.service.web.entity;

import cn.hutool.core.util.ObjectUtil;
import com.lanyuanxiaoyao.service.common.entity.FlinkJob;
import com.lanyuanxiaoyao.service.common.entity.RunMeta;
import com.lanyuanxiaoyao.service.common.entity.TableMeta;
import com.lanyuanxiaoyao.service.common.utils.NameHelper;

/**
 * 表展示
 *
 * @author lanyuanxiaoyao
 * @date 2023-04-24
 */
public class TableVO {
    private final String flinkJobId;
    private final FlinkJob flinkJob;
    private final TableMeta tableMeta;
    private final SyncStateVO syncState;
    private final Boolean syncRunning;
    private final RunMeta syncRuntime;
    private final Boolean compactionRunning;
    private final RunMeta compactionRuntime;
    private String syncJobName;
    private YarnApplicationVO syncApp;
    private String compactionJobName;
    private YarnApplicationVO compactionApp;

    public TableVO(FlinkJob flinkJob, TableMeta tableMeta, SyncStateVO syncState, Boolean syncRunning, RunMeta syncRuntime, Boolean compactionRunning, RunMeta compactionRuntime) {
        this.flinkJobId = ObjectUtil.isNull(flinkJob) ? null : flinkJob.getId().toString();
        this.flinkJob = flinkJob;
        this.tableMeta = tableMeta;
        this.syncRunning = syncRunning;
        this.syncRuntime = syncRuntime;
        this.compactionRunning = compactionRunning;
        this.compactionRuntime = compactionRuntime;
        if (ObjectUtil.isNotNull(flinkJob) && ObjectUtil.isNotNull(tableMeta)) {
            this.syncJobName = NameHelper.syncJobName(this.flinkJob.getId(), this.flinkJob.getName());
            this.compactionJobName = NameHelper.compactionJobName(this.flinkJob.getId(), this.tableMeta.getAlias());
        }
        this.syncState = syncState;
    }

    public String getFlinkJobId() {
        return flinkJobId;
    }

    public FlinkJob getFlinkJob() {
        return flinkJob;
    }

    public TableMeta getTableMeta() {
        return tableMeta;
    }

    public Boolean getSyncRunning() {
        return syncRunning;
    }

    public RunMeta getSyncRuntime() {
        return syncRuntime;
    }

    public Boolean getCompactionRunning() {
        return compactionRunning;
    }

    public RunMeta getCompactionRuntime() {
        return compactionRuntime;
    }

    public String getSyncJobName() {
        return syncJobName;
    }

    public YarnApplicationVO getSyncApp() {
        return syncApp;
    }

    public void setSyncApp(YarnApplicationVO syncApp) {
        this.syncApp = syncApp;
    }

    public String getCompactionJobName() {
        return compactionJobName;
    }

    public YarnApplicationVO getCompactionApp() {
        return compactionApp;
    }

    public void setCompactionApp(YarnApplicationVO compactionApp) {
        this.compactionApp = compactionApp;
    }

    public SyncStateVO getSyncState() {
        return syncState;
    }

    @Override
    public String toString() {
        return "TableVO{" +
                "flinkJobId='" + flinkJobId + '\'' +
                ", flinkJob=" + flinkJob +
                ", tableMeta=" + tableMeta +
                ", syncState=" + syncState +
                ", syncRunning=" + syncRunning +
                ", syncRuntime=" + syncRuntime +
                ", compactionRunning=" + compactionRunning +
                ", compactionRuntime=" + compactionRuntime +
                ", syncJobName='" + syncJobName + '\'' +
                ", syncApp=" + syncApp +
                ", compactionJobName='" + compactionJobName + '\'' +
                ", compactionApp=" + compactionApp +
                '}';
    }
}
