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

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import com.ruoyi.common.exception.ServiceException;

@DisplayName("疫病诊疗标准校验 EpidemicTreatmentStandardValidation")
class EpidemicTreatmentStandardValidationTest
{

    @Test
    @DisplayName("标准名称长度 1～20")
    void standardName()
    {
        assertThrows(ServiceException.class, () -> EpidemicTreatmentStandardValidation.validateStandardName(null));
        assertThrows(ServiceException.class, () -> EpidemicTreatmentStandardValidation.validateStandardName(""));
        assertDoesNotThrow(() -> EpidemicTreatmentStandardValidation.validateStandardName("甲"));
        assertDoesNotThrow(() -> EpidemicTreatmentStandardValidation.validateStandardName(repeat('a', 20)));
        assertThrows(ServiceException.class, () -> EpidemicTreatmentStandardValidation.validateStandardName(repeat('a', 21)));
    }

    @Test
    @DisplayName("简介 ≤50")
    void introduction()
    {
        assertDoesNotThrow(() -> EpidemicTreatmentStandardValidation.validateIntroduction(null));
        assertDoesNotThrow(() -> EpidemicTreatmentStandardValidation.validateIntroduction(repeat('b', 50)));
        assertThrows(ServiceException.class, () -> EpidemicTreatmentStandardValidation.validateIntroduction(repeat('b', 51)));
    }

    @Test
    @DisplayName("标准类型编码非空且长度≤32")
    void standardType()
    {
        assertThrows(ServiceException.class, () -> EpidemicTreatmentStandardValidation.validateStandardType(null));
        assertThrows(ServiceException.class, () -> EpidemicTreatmentStandardValidation.validateStandardType(""));
        assertThrows(ServiceException.class, () -> EpidemicTreatmentStandardValidation.validateStandardType(repeat('c', 33)));
        assertDoesNotThrow(() -> EpidemicTreatmentStandardValidation.validateStandardType("001013"));
    }

    @Test
    @DisplayName("正文附件校验：非法路径")
    void validateContent_badPath()
    {
        assertThrows(ServiceException.class,
                () -> EpidemicTreatmentStandardValidation.validateContentAttachment("a.pdf", "/wrong/a.pdf"));
    }

    private static String repeat(char c, int n)
    {
        char[] a = new char[n];
        java.util.Arrays.fill(a, c);
        return new String(a);
    }
}
