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;

/**
 * YZ-BZ-UT-008～010：参数与附件路径校验
 */
@DisplayName("养殖标准校验 BreedingStandardValidation")
class BreedingStandardValidationTest
{

    @Test
    @DisplayName("YZ-BZ-UT-008 标准名称长度 1～20")
    void ut008_standardName()
    {
        assertThrows(ServiceException.class, () -> BreedingStandardValidation.validateStandardName(null));
        assertThrows(ServiceException.class, () -> BreedingStandardValidation.validateStandardName(""));
        assertDoesNotThrow(() -> BreedingStandardValidation.validateStandardName("甲"));
        assertDoesNotThrow(() -> BreedingStandardValidation.validateStandardName("12"));
        assertDoesNotThrow(() -> BreedingStandardValidation.validateStandardName(repeat('a', 20)));
        assertThrows(ServiceException.class, () -> BreedingStandardValidation.validateStandardName(repeat('a', 21)));
    }

    @Test
    @DisplayName("YZ-BZ-UT-009 简介 ≤50")
    void ut009_introduction()
    {
        assertDoesNotThrow(() -> BreedingStandardValidation.validateIntroduction(null));
        assertDoesNotThrow(() -> BreedingStandardValidation.validateIntroduction(""));
        assertDoesNotThrow(() -> BreedingStandardValidation.validateIntroduction(repeat('b', 50)));
        assertThrows(ServiceException.class, () -> BreedingStandardValidation.validateIntroduction(repeat('b', 51)));
    }

    @Test
    @DisplayName("YZ-BZ-UT-010 标准类型编码非空")
    void ut010_standardType()
    {
        assertThrows(ServiceException.class, () -> BreedingStandardValidation.validateStandardType(null));
        assertThrows(ServiceException.class, () -> BreedingStandardValidation.validateStandardType(""));
        assertDoesNotThrow(() -> BreedingStandardValidation.validateStandardType("001001"));
    }

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