package cn.reghao.bnt.common.agent.app.iface.impl;

import cn.reghao.bnt.common.agent.app.iface.AppStat;
import cn.reghao.bnt.common.msg.constant.PackType;
import cn.reghao.bnt.common.msg.event.EvtAppStat;
import cn.reghao.bnt.common.msg.event.EvtAppStatResult;

import java.util.List;

/**
 * @author reghao
 * @date 2023-03-06 16:19:24
 */
public class AppStatImpl implements AppStat {
    private final DockerApp dockerApp;

    public AppStatImpl(DockerApp dockerApp) {
        this.dockerApp = dockerApp;
    }

    @Override
    public EvtAppStatResult start(EvtAppStat evtAppStat) throws Exception {
        String packType = evtAppStat.getPackType();
        String appId = evtAppStat.getAppId();

        if (packType.equals(PackType.docker.name())) {
            return dockerApp.start(appId);
        } else {
            throw new Exception("zip 打包没有实现");
        }
    }

    @Override
    public EvtAppStatResult stop(EvtAppStat evtAppStat) throws Exception {
        String packType = evtAppStat.getPackType();
        String appId = evtAppStat.getAppId();

        if (packType.equals(PackType.docker.name())) {
            return dockerApp.stop(appId);
        } else {
            throw new Exception("zip 打包没有实现");
        }
    }

    @Override
    public EvtAppStatResult restart(EvtAppStat evtAppStat) throws Exception {
        String packType = evtAppStat.getPackType();
        String appId = evtAppStat.getAppId();

        if (packType.equals(PackType.docker.name())) {
            return dockerApp.restart(appId);
        } else {
            throw new Exception("zip 打包没有实现");
        }
    }

    @Override
    public EvtAppStatResult stat(EvtAppStat evtAppStat) throws Exception {
        String packType = evtAppStat.getPackType();
        String appId = evtAppStat.getAppId();

        if (packType.equals(PackType.docker.name())) {
            return dockerApp.stat(appId);
        } else {
            throw new Exception("zip 打包没有实现");
        }
    }

    @Override
    public List<EvtAppStatResult> stat() throws Exception {
        return dockerApp.stat();
    }
}
