package com.ruoyi.web.modules.industrypolicy.support;

/**
 * 产业政策宣传发布状态与附件白名单。
 */
public final class IndustryPolicyPublicityRules
{
    private IndustryPolicyPublicityRules()
    {
    }

    public static boolean canEdit(Integer publishStatus)
    {
        return publishStatus != null && publishStatus == 0;
    }

    public static boolean canDelete(Integer publishStatus)
    {
        return publishStatus != null && publishStatus == 0;
    }

    public static boolean canPublish(Integer publishStatus)
    {
        return publishStatus != null && publishStatus == 0;
    }

    public static boolean canOffline(Integer publishStatus)
    {
        return publishStatus != null && publishStatus == 1;
    }

    public static boolean isPolicyFileExtensionAllowed(String filenameOrPath)
    {
        String ext = extensionOf(filenameOrPath);
        return ext.equals("pdf") || ext.equals("md") || ext.equals("doc") || ext.equals("docx")
                || ext.equals("xls") || ext.equals("xlsx") || ext.equals("ppt") || ext.equals("pptx");
    }

    public static boolean isCoverExtensionAllowed(String filenameOrPath)
    {
        String ext = extensionOf(filenameOrPath);
        return ext.equals("jpg") || ext.equals("jpeg") || ext.equals("png");
    }

    public static String extensionOf(String name)
    {
        if (name == null)
        {
            return "";
        }
        int i = name.lastIndexOf('.');
        if (i < 0 || i == name.length() - 1)
        {
            return "";
        }
        return name.substring(i + 1).toLowerCase();
    }
}
