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;

@DisplayName("生长与出栏标准规则 GrowthSlaughterStandardRules")
class GrowthSlaughterStandardRulesTest
{

    @Test
    @DisplayName("合法/非法状态组合")
    void stateCombos()
    {
        assertTrue(GrowthSlaughterStandardRules.isValidStateCombo(0, 0));
        assertTrue(GrowthSlaughterStandardRules.isValidStateCombo(0, 1));
        assertTrue(GrowthSlaughterStandardRules.isValidStateCombo(1, 1));
        assertFalse(GrowthSlaughterStandardRules.isValidStateCombo(1, 0));
        assertFalse(GrowthSlaughterStandardRules.isValidStateCombo(2, 0));
    }

    @Test
    @DisplayName("仅未发布且未同步可编辑")
    void canEdit()
    {
        assertTrue(GrowthSlaughterStandardRules.canEdit(0, 0));
        assertFalse(GrowthSlaughterStandardRules.canEdit(0, 1));
        assertFalse(GrowthSlaughterStandardRules.canEdit(1, 1));
        assertFalse(GrowthSlaughterStandardRules.canEdit(null, 0));
    }

    @ParameterizedTest
    @CsvSource({
        "0, 0, true",
        "0, 1, false",
        "1, 1, false"
    })
    @DisplayName("同步前置")
    void canSyncKb(int p, int k, boolean expected)
    {
        assertEquals(expected, GrowthSlaughterStandardRules.canSyncKb(p, k));
    }

    @ParameterizedTest
    @CsvSource({
        "0, 1, true",
        "0, 0, false",
        "1, 1, false"
    })
    @DisplayName("移出知识库前置")
    void canRemoveKb(int p, int k, boolean expected)
    {
        assertEquals(expected, GrowthSlaughterStandardRules.canRemoveKb(p, k));
    }

    @ParameterizedTest
    @CsvSource({
        "0, 1, true",
        "0, 0, false",
        "1, 1, false"
    })
    @DisplayName("发布前置")
    void canPublish(int p, int k, boolean expected)
    {
        assertEquals(expected, GrowthSlaughterStandardRules.canPublish(p, k));
    }

    @Test
    @DisplayName("下架前置")
    void canOffline()
    {
        assertTrue(GrowthSlaughterStandardRules.canOffline(1));
        assertFalse(GrowthSlaughterStandardRules.canOffline(0));
        assertFalse(GrowthSlaughterStandardRules.canOffline(null));
    }

    @Test
    @DisplayName("删除前置")
    void canDelete()
    {
        assertTrue(GrowthSlaughterStandardRules.canDelete(0, 0));
        assertTrue(GrowthSlaughterStandardRules.canDelete(0, 1));
        assertFalse(GrowthSlaughterStandardRules.canDelete(1, 1));
        assertFalse(GrowthSlaughterStandardRules.canDelete(1, 0));
    }

    @Test
    @DisplayName("正文后缀白名单")
    void contentExt()
    {
        assertTrue(GrowthSlaughterStandardRules.isContentExtensionAllowed("a.pdf"));
        assertTrue(GrowthSlaughterStandardRules.isContentExtensionAllowed("readme.md"));
        assertTrue(GrowthSlaughterStandardRules.isContentExtensionAllowed("slides.pptx"));
        assertFalse(GrowthSlaughterStandardRules.isContentExtensionAllowed("legacy.ppt"));
        assertFalse(GrowthSlaughterStandardRules.isContentExtensionAllowed("a.exe"));
    }

    @Test
    @DisplayName("封面后缀")
    void coverExt()
    {
        assertTrue(GrowthSlaughterStandardRules.isCoverExtensionAllowed("/profile/upload/1.JPEG"));
        assertFalse(GrowthSlaughterStandardRules.isCoverExtensionAllowed("a.bmp"));
    }
}
