package com.qmth.teachcloud.common.enums;

import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * @Description: 上传文件类型
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2020/7/15
 */
public enum UploadFileEnum {
    /**
     * 客户端
     */
    PAPER("paper", "private", ""),
    /**
     * 系统相关
     */
    UPLOAD("upload", "private", ""),
    /**
     * 导入导出
     */
    FILE("file", "public", ""),
    /**
     * 打印pdf相关
     */
    PDF("pdf", "private", ""),
    /**
     * 题卡图片
     */
    IMAGE("image", "private", ""),
    /**
     * 题卡html文件
     */
    HTML("html", "private", ""),
    /**
     * 阅卷考生题卡原图（path:{uploadType}/{examId}/{coursePaperId}/{studentCode}/时间戳-{pageIndex}.jpg）
     */
    SHEET("sheet", "private", "%s/%d/%s/%s/%d-%d.%s"),
    /**
     * 卡格式文件（path:{uploadType}/{examId}/{coursePaperId}/{number}.json）
     */
    CARD("card", "private", "%s/%d/%s/%d.%s"),
    /**
     * 适配后卡格式文件（path:{uploadType}/{examId}/{coursePaperId}/adapt/{number}.json）
     */
    ADAPT("adapt", "private", "%s/%d/%s/adapt/%d.%s"),
    /**
     * 签到表文件（path:{uploadType}/{examId}/{coursePaperId}/{packageCode}-{packageNo}.jpg）
     */
    PACKAGE("package", "private", "%s/%d/%s/%s-%s.%s"),
    /**
     * 归档文件（path:{uploadType}/{examId}/{paperNumber}/{documentType}-{no}.{format}）
     */
    DOCUMENT("document", "private", "%s/%d/%s/%s-%s.%s"),
    /**
     * 扫描端日志文件（path:{uploadType}/{schoolCode}/{deviceCode}/{fileName}）
     */
    LOG("log", "public", "%s/%s/%s/%s"),
    /**
     * 安装包/升级包
     */
    UPGRADE("upgrade", "public", "");


    private String title;
    private String fssType;
    private String pattern;

    UploadFileEnum(String title, String fssType, String pattern) {
        this.title = title;
        this.fssType = fssType;
        this.pattern = pattern;
    }

    public String getTitle() {
        return title;
    }

    public String getFssType() {
        return fssType;
    }

    public String getPattern() {
        return pattern;
    }

    /**
     * 状态转换 toName
     *
     * @param title
     * @return
     */
    public static String convertToName(String title) {
        for (UploadFileEnum e : UploadFileEnum.values()) {
            if (Objects.equals(title, e.getTitle())) {
                return e.name();
            }
        }
        return null;
    }

    /**
     * 状态转换 toName
     *
     * @param title
     * @return
     */
    public static String convertToFssType(String title) {
        for (UploadFileEnum e : UploadFileEnum.values()) {
            if (Objects.equals(title.toLowerCase(), e.getTitle())) {
                return e.getFssType();
            }
        }
        return null;
    }

    public String getPath(Object... param) {
        if (StringUtils.isBlank(pattern)) {
            return null;
        }
        return String.format(pattern, param);
    }
}
