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

/**
 * 共同富裕项目发布状态与附件白名单。
 */
public final class CommonProsperityProjectRules
{
    private CommonProsperityProjectRules()
    {
    }

    /** 实施年限可选：当前年向前回看年数（含当前年共 LOOKBACK+1=5 个自然年） */
    public static final int IMPL_YEAR_LOOKBACK = 4;

    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 isOperationImageExtensionAllowed(String filenameOrPath)
    {
        String ext = extensionOf(filenameOrPath);
        return ext.equals("jpg") || ext.equals("jpeg") || ext.equals("png");
    }

    public static boolean isCoverExtensionAllowed(String filenameOrPath)
    {
        return isOperationImageExtensionAllowed(filenameOrPath);
    }

    public static boolean isVideoExtensionAllowed(String filenameOrPath)
    {
        String ext = extensionOf(filenameOrPath);
        return ext.equals("mp4");
    }

    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();
    }
}
