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("疫病诊疗标准规则 EpidemicTreatmentStandardRules")
class EpidemicTreatmentStandardRulesTest
{

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

    @Test
    @DisplayName("仅未发布且未同步可编辑")
    void canEdit()
    {
        assertTrue(EpidemicTreatmentStandardRules.canEdit(0, 0));
        assertFalse(EpidemicTreatmentStandardRules.canEdit(0, 1));
        assertFalse(EpidemicTreatmentStandardRules.canEdit(1, 1));
        assertFalse(EpidemicTreatmentStandardRules.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, EpidemicTreatmentStandardRules.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, EpidemicTreatmentStandardRules.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, EpidemicTreatmentStandardRules.canPublish(p, k));
    }

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

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

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

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