package com.lanyuanxiaoyao.service.web.entity;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnQueue;
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnRootQueue;
import org.eclipse.collections.api.list.ImmutableList;

/**
 * @author lanyuanxiaoyao
 * @date 2023-05-05
 */
public class YarnClusterVO {
    @JsonIgnore
    private final YarnRootQueue yarnRootQueue;
    private final ImmutableList<YarnQueue> children;

    public YarnClusterVO(YarnRootQueue yarnRootQueue, ImmutableList<YarnQueue> children) {
        this.yarnRootQueue = yarnRootQueue;
        this.children = children;
    }

    public Boolean isRoot() {
        return true;
    }

    public String getCluster() {
        return yarnRootQueue.getCluster();
    }

    public String getQueueName() {
        return StrUtil.format("{} ({})", yarnRootQueue.getQueueName(), yarnRootQueue.getCluster());
    }

    public String getType() {
        return yarnRootQueue.getType();
    }

    public Float getAbsoluteCapacity() {
        return yarnRootQueue.getCapacity();
    }

    public Float getAbsoluteUsedCapacity() {
        return yarnRootQueue.getUsedCapacity();
    }

    public Float getAbsoluteMaxCapacity() {
        return yarnRootQueue.getMaxCapacity();
    }

    public String getWebUrl() {
        return yarnRootQueue.getWebUrl();
    }

    public ImmutableList<YarnQueue> getChildren() {
        return children;
    }

    @Override
    public String toString() {
        return "YarnClusterVO{" +
                "yarnRootQueue=" + yarnRootQueue +
                ", yarnQueues=" + children +
                '}';
    }
}
