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("生长与出栏标准校验 GrowthSlaughterStandardValidation")
class GrowthSlaughterStandardValidationTest
{

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

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

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

    @Test
    @DisplayName("正文附件校验：非法路径")
    void validateContent_badPath()
    {
        assertThrows(ServiceException.class,
                () -> GrowthSlaughterStandardValidation.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);
    }
}
