package com.qmth.boot.core.ai.model.ocr;

/**
 * 图片类型
 */
public enum ImageType {

    JPG("data:image/jpeg;base64,"),

    PNG("data:image/png;base64,"),

    WEBP("data:image/webp;base64,");

    private String base64Prefix;

    ImageType(String base64Prefix) {
        this.base64Prefix = base64Prefix;
    }

    public String getBase64Prefix() {
        return base64Prefix;
    }

    public static ImageType find(String fileName) {
        String imgSuffix = getFileSuffix(fileName);
        if (imgSuffix == null) {
            return null;
        }

        switch (imgSuffix) {
            case ".jpg":
            case ".jpeg":
                return ImageType.JPG;
            case ".png":
                return ImageType.PNG;
            case ".webp":
                return ImageType.WEBP;
        }
        return null;
    }

    /**
     * 获取文件后缀名(包含".")
     */
    public static String getFileSuffix(String fileName) {
        if (fileName != null) {
            int index = fileName.lastIndexOf(".");
            if (index > -1) {
                return fileName.substring(index).toLowerCase();
            }
        }
        return null;
    }

}
