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;

/**
 * YZ-BZ-UT-001～007、011～012：状态矩阵与附件白名单
 */
@DisplayName("养殖标准规则 BreedingStandardRules")
class BreedingStandardRulesTest
{

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

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

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

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

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

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

    @Test
    @DisplayName("YZ-BZ-UT-007 删除前置（已发布不可删；未发布已同步可删=内置移出）")
    void ut007_canDelete()
    {
        assertTrue(BreedingStandardRules.canDelete(0, 0));
        assertTrue(BreedingStandardRules.canDelete(0, 1));
        assertFalse(BreedingStandardRules.canDelete(2, 0));
        assertFalse(BreedingStandardRules.canDelete(1, 1));
        assertFalse(BreedingStandardRules.canDelete(1, 0));
    }

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

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