package com.mortals.xhx.common.code;

import java.util.LinkedHashMap;
import java.util.Map;


public enum Base64TypeEnum {
    // 文件类型
    BASE64_FILETYPE_DOC("doc", "data:application/msword;base64"),
    BASE64_FILETYPE_DOCX("docx", "data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64"),
    BASE64_FILETYPE_XLS("xls", "data:application/vnd.ms-excel;base64,"),
    BASE64_FILETYPE_XLSX("xlsx", "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64"),
    BASE64_FILETYPE_PDF("pdf", "data:application/pdf;base64"),
    BASE64_FILETYPE_PPT("ppt", "data:application/vnd.ms-powerpoint;base64"),
    BASE64_FILETYPE_PPTX("pptx", "data:application/vnd.openxmlformats-officedocument.presentationml.presentation;base64"),
    BASE64_FILETYPE_TXT("txt", "data:text/plain;base64"),
    // 图片类型
    BASE64_FILETYPE_PNG("png", "data:image/png;base64"),
    BASE64_FILETYPE_JPG("jpg", "data:image/jpeg;base64"),
    BASE64_FILETYPE_JPEG("jpeg", "data:image/jpeg;base64"),
    BASE64_FILETYPE_GIF("gif", "data:image/gif;base64"),
    BASE64_FILETYPE_SVG("svg", "data:image/svg+xml;base64"),
    BASE64_FILETYPE_ICO("ico", "data:image/x-icon;base64"),
    BASE64_FILETYPE_BMP("bmp", "data:image/bmp;base64"),
    // 二进制流
    BASE64_FILETYPE_OCTET_STREAM("octet-stream", "data:application/octet-stream;base64"),
    ;

    private String value;
    private String desc;

    Base64TypeEnum(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public String getValue() {
        return this.value;
    }

    public String getDesc() {
        return this.desc;
    }

    public static Base64TypeEnum getByValue(String value) {
        for (Base64TypeEnum BusizTypeEnum : Base64TypeEnum.values()) {
            if (BusizTypeEnum.getValue().equals(value)) {
                return BusizTypeEnum;
            }
        }
        return null;
    }

    /**
     * 获取Map集合
     *
     * @param eItem 不包含项
     * @return
     */
    public static Map<String, String> getEnumMap(String... eItem) {
        Map<String, String> resultMap = new LinkedHashMap<>();
        for (Base64TypeEnum item : Base64TypeEnum.values()) {
            try {
                boolean hasE = false;
                for (String e : eItem) {
                    if (item.getValue() == e) {
                        hasE = true;
                        break;
                    }
                }
                if (!hasE) {
                    resultMap.put(item.getValue() + "", item.getDesc());
                }
            } catch (Exception ex) {

            }
        }
        return resultMap;
    }
}