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;

/**
 * SS-BZ-UT-001～007、011～012
 */
@DisplayName("设备实施作业标准规则 EquipmentWorkStandardRules")
class EquipmentWorkStandardRulesTest
{

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

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

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

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

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

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

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

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

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