export function errorMessage(errData) {
    let prefix = "";
    console.log(errData.response);
    if (errData.response.data.err) {
        return prefix + errData.response.data.msg;
    }
    return prefix + (errData.statusText ?? "未知错误");
}

export function problemTypeOptions(containAll = false){
    const options = containAll ? [{ label: "所有题目", value: "" }] : [];
    options.push(
      { label: "Java", value: "JAVA" },
      { label: "Java数据库", value: "JAVA_DATABASE" },
      { label: "Java覆盖测试", value: "JAVA_COVERAGE" },
      { label: "Python", value: "PYTHON" },
      { label: "Python覆盖测试", value: "PYTHON_COVERAGE" },
      { label: "Java变异覆盖测试", value: "JAVA_MUTATION" },
      { label: "Java数据结构", value: "JAVA_DATA_STRUCTURE" },
      { label: "Java计算机组成原理", value: "JAVA_COMPUTER_ORGANIZATION" },
      { label: "Java软件设计", value: "JAVA_COMPUTER_ORGANIZATION" },
      { label: "C++", value: "CPP" }
    );
    return options;
}

export function formatTimestamp(timestamp){
    if (timestamp) {
        const date = new Date(timestamp * 1000);
        return `${date.getFullYear()}/${String(date.getMonth() + 1).padStart(
          2,
          "0"
        )}/${String(date.getDate()).padStart(2, "0")} ${String(
          date.getHours()
        ).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
    }
    return "";
}

export function problemTypeToTagContent(type) {
    switch (type) {
        case "JAVA":
            return "Java";
        case "JAVA_JVM":
            return "Java虚拟机";
        case "JAVA_COVERAGE":
            return "Java覆盖测试";
        case "PYTHON":
            return "Python";
        case "PYTHON_COVERAGE":
            return "Python覆盖测试";
        case "JAVA_MUTATION":
            return "Java变异覆盖测试";
        case "JAVA_DATA_STRUCTURE":
            return "java数据结构";
        case "JAVA_COMPUTER_ORGANIZATION":
            return "java数据结构";
        case "JAVA_DATABASE":
            return "Java数据库";
        case "JAVA_SOFTWARE_DESIGN":
            return "Java软件设计";
    }
    return type;
}

export function examStatusToTagType(status) {
    switch (status) {
        case "READY":
            return "";
        case "AVAILABLE":
            return "success";
        case "FINISHED":
            return "warning";
        case "UNAVAILABLE":
            return "danger";
    }
    return "info";
}

export function examStatusToTagContent(status) {
    switch (status) {
        case "PREPARING":
            return "准备中";
        case "UNAVAILABLE":
            return "初始化失败";
        case "READY":
            return "尚未开始";
        case "AVAILABLE":
            return "正在进行";
        case "FINISHED":
            return "已结束";
        case "CLOSED":
            return "已关闭";
    }
    return "未知状态";
}

export function buildStatusToTagType(status) {
    switch (status) {
        case "RUNNING":
            return "";
        case "SUCCESS":
            return "success";
        case "UNSTABLE":
            return "warning";
        case "FAILURE":
        case "TIMEOUT":
            return "danger";
    }
    return "info";
}

export function buildStatusToTagContent(status) {
    switch (status) {
        case "SUCCESS":
            return "所有用例通过";
        case "UNSTABLE":
            return "有用例未通过";
        case "FAILURE":
            return "编译或运行失败";
        case "TIMEOUT":
            return "运行超时";
        case "WAITING":
            return "等待运行";
        case "RUNNING":
            return "正在运行";
    }
    return "未知状态";
}

