package com.microservices.mon.k8s.domain;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;


@Data
@ApiModel("应用状态")
public class K8sApplicationAndPodState {

    @ApiModelProperty(value = "状态标识")
    private String name;

    @ApiModelProperty(value = "应用展示名称（中文）")
    private String alias;

    @ApiModelProperty(value = "是否错误")
    private Boolean isError;

    @ApiModelProperty(value = "状态消息")
    private String message;

    public static K8sApplicationAndPodState k8sApplicationStopState(String stateName) {
        K8sApplicationAndPodState state = new K8sApplicationAndPodState();
        state.setName(stateName);
        state.setIsError(false);
        state.setMessage("");
        state.setApplicationAliasByName(stateName);
        return state;
    }

    public void setApplicationAliasByName(String name) {
        this.name = name;
        if ("active".equalsIgnoreCase(name)) {
            this.alias = "运行中";
        } else if ("updating".equalsIgnoreCase(name)) {
            this.alias = "更新中";
        } else if ("in-progress".equalsIgnoreCase(name)) {
            this.alias = "处理中";
        } else if ("error".equalsIgnoreCase(name)) {
            this.alias = "运行失败";
        } else if ("paused".equalsIgnoreCase(name)) {
            this.alias = "暂停编排";
        } else if ("pending".equalsIgnoreCase(name)) {
            this.alias = "等待中";
        } else if ("stop".equalsIgnoreCase(name)) {
            this.alias = "已停止运行";
        } else {
            this.alias = name;
        }
    }

    public void setPodAliasAndErrorByName(String name) {
        this.name = name;
        this.isError=true;

        if ("imagePullBackOff".equalsIgnoreCase(name)) {
            this.alias = "镜像拉取失败";
        } else if ("pending".equalsIgnoreCase(name)) {
            this.alias = "等待中";
            this.isError=false;
        } else if ("running".equalsIgnoreCase(name)) {
            this.alias = "运行中";
            this.isError=false;
        } else if ("podScheduled".equalsIgnoreCase(name)) {
            this.alias = "容器已调度";
            this.isError=false;
        } else if ("containersReady".equalsIgnoreCase(name)) {
            this.alias = "容器已就绪";
            this.isError=false;
        } else if ("initialized".equalsIgnoreCase(name)) {
            this.alias = "容器已初始化";
            this.isError=false;
        } else if ("ready".equalsIgnoreCase(name)) {
            this.alias = "容器已准备就绪";
            this.isError=false;
        } else if ("crashLoopBackOff".equalsIgnoreCase(name)) {
            this.alias = "容器崩溃循环重启";
        } else if ("invalidImageName".equalsIgnoreCase(name)) {
            this.alias = "无法解析镜像名称";
        } else if ("imageInspectError".equalsIgnoreCase(name)) {
            this.alias = "无法校验镜像";
        } else if ("errImageNeverPull".equalsIgnoreCase(name)) {
            this.alias = "策略禁止拉取镜像";
        } else if ("registryUnavailable".equalsIgnoreCase(name)) {
            this.alias = "连接不到镜像中心";
        } else if ("errImagePull".equalsIgnoreCase(name)) {
            this.alias = "拉取镜像出错";
        } else if ("createContainerConfigError".equalsIgnoreCase(name)) {
            this.alias = "不能创建容器配置";
        } else if ("createContainerError".equalsIgnoreCase(name)) {
            this.alias = "创建容器失败";
        } else if ("runContainerError".equalsIgnoreCase(name)) {
            this.alias = "启动容器失败";
        } else if ("postStartHookError".equalsIgnoreCase(name)) {
            this.alias = "执行hook报错";
        } else if ("containersNotInitialized".equalsIgnoreCase(name)) {
            this.alias = "容器未初始化完毕";
        } else if ("containersNotReady".equalsIgnoreCase(name)) {
            this.alias = "容器未准备完毕";
        } else if ("containerCreating".equalsIgnoreCase(name)) {
            this.alias = "容器创建中";
            this.isError=false;
        } else if ("podInitializing".equalsIgnoreCase(name)) {
            this.alias = "Pod 初始化中";
            this.isError=false;
        } else if ("dockerDaemonNotReady".equalsIgnoreCase(name)) {
            this.alias = "Docker 未完全启动";
        } else if ("networkPluginNotReady".equalsIgnoreCase(name)) {
            this.alias = "网络插件未完全启动";
        } else if ("evicted".equalsIgnoreCase(name)) {
            this.alias = "Pod 被驱赶";
        } else if ("terminating".equalsIgnoreCase(name)) {
            this.alias = "删除中";
            this.isError=false;
        } else {
            this.alias = name;
        }
    }
}
