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

/**
 * 综合牧业知识库：入库状态与附件白名单（无发布态）。
 */
public final class LivestockKnowledgeRules
{
    public static final int KB_SYNC_NOT_IN = 0;

    public static final int KB_SYNC_IN = 1;

    public static final String DEL_FLAG_NORMAL = "0";

    public static final String DEL_FLAG_DELETED = "2";

    private LivestockKnowledgeRules()
    {
    }

    public static boolean isValidKbSyncStatus(Integer kbSyncStatus)
    {
        return kbSyncStatus != null && (kbSyncStatus == KB_SYNC_NOT_IN || kbSyncStatus == KB_SYNC_IN);
    }

    public static boolean canEdit(Integer kbSyncStatus)
    {
        return kbSyncStatus != null && kbSyncStatus == KB_SYNC_NOT_IN;
    }

    public static boolean canDelete(Integer kbSyncStatus)
    {
        return kbSyncStatus != null && kbSyncStatus == KB_SYNC_NOT_IN;
    }

    public static boolean canSyncKb(Integer kbSyncStatus)
    {
        return kbSyncStatus != null && kbSyncStatus == KB_SYNC_NOT_IN;
    }

    public static boolean canRemoveKb(Integer kbSyncStatus)
    {
        return kbSyncStatus != null && kbSyncStatus == KB_SYNC_IN;
    }

    public static boolean isContentExtensionAllowed(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("pptx");
    }

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