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

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

/**
 * WF-BZ-UT-001～007、011～012：状态矩阵与附件白名单
 */
@DisplayName("饲喂标准规则 FeedingStandardRules")
class FeedingStandardRulesTest
{

    @Test
    @DisplayName("WF-BZ-UT-001 合法/非法状态组合")
    void ut001_stateCombos()
    {
        assertTrue(FeedingStandardRules.isValidStateCombo(0, 0));
        assertTrue(FeedingStandardRules.isValidStateCombo(0, 1));
        assertTrue(FeedingStandardRules.isValidStateCombo(1, 1));
        assertFalse(FeedingStandardRules.isValidStateCombo(1, 0));
        assertFalse(FeedingStandardRules.isValidStateCombo(2, 0));
    }

    @Test
    @DisplayName("WF-BZ-UT-002 仅未发布且未同步可编辑")
    void ut002_canEdit()
    {
        assertTrue(FeedingStandardRules.canEdit(0, 0));
        assertFalse(FeedingStandardRules.canEdit(0, 1));
        assertFalse(FeedingStandardRules.canEdit(1, 1));
        assertFalse(FeedingStandardRules.canEdit(1, null));
        assertFalse(FeedingStandardRules.canEdit(null, 0));
    }

    @ParameterizedTest
    @CsvSource({
        "0, 0, true",
        "0, 1, false",
        "1, 1, false"
    })
    @DisplayName("WF-BZ-UT-003 同步前置")
    void ut003_canSyncKb(int p, int k, boolean expected)
    {
        assertEquals(expected, FeedingStandardRules.canSyncKb(p, k));
    }

    @ParameterizedTest
    @CsvSource({
        "0, 1, true",
        "0, 0, false",
        "1, 1, false"
    })
    @DisplayName("WF-BZ-UT-004 移出知识库前置")
    void ut004_canRemoveKb(int p, int k, boolean expected)
    {
        assertEquals(expected, FeedingStandardRules.canRemoveKb(p, k));
    }

    @ParameterizedTest
    @CsvSource({
        "0, 1, true",
        "0, 0, false",
        "1, 1, false"
    })
    @DisplayName("WF-BZ-UT-005 发布前置")
    void ut005_canPublish(int p, int k, boolean expected)
    {
        assertEquals(expected, FeedingStandardRules.canPublish(p, k));
    }

    @Test
    @DisplayName("WF-BZ-UT-006 下架前置")
    void ut006_canOffline()
    {
        assertTrue(FeedingStandardRules.canOffline(1));
        assertFalse(FeedingStandardRules.canOffline(0));
        assertFalse(FeedingStandardRules.canOffline(null));
    }

    @Test
    @DisplayName("WF-BZ-UT-007 删除前置")
    void ut007_canDelete()
    {
        assertTrue(FeedingStandardRules.canDelete(0, 0));
        assertTrue(FeedingStandardRules.canDelete(0, 1));
        assertFalse(FeedingStandardRules.canDelete(1, 1));
        assertFalse(FeedingStandardRules.canDelete(1, 0));
    }

    @Test
    @DisplayName("WF-BZ-UT-011 正文后缀白名单")
    void ut011_contentExt()
    {
        assertTrue(FeedingStandardRules.isContentExtensionAllowed("a.pdf"));
        assertTrue(FeedingStandardRules.isContentExtensionAllowed("readme.md"));
        assertTrue(FeedingStandardRules.isContentExtensionAllowed("slides.pptx"));
        assertFalse(FeedingStandardRules.isContentExtensionAllowed("legacy.ppt"));
        assertFalse(FeedingStandardRules.isContentExtensionAllowed("a.exe"));
    }

    @Test
    @DisplayName("WF-BZ-UT-012 封面后缀")
    void ut012_coverExt()
    {
        assertTrue(FeedingStandardRules.isCoverExtensionAllowed("/profile/upload/1.JPEG"));
        assertFalse(FeedingStandardRules.isCoverExtensionAllowed("a.bmp"));
    }
}
