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("WithdrawalPeriodStandardValidation")
class WithdrawalPeriodStandardValidationTest
{

    @Test
    @DisplayName("药物名称 1～20")
    void drugName()
    {
        assertThrows(ServiceException.class, () -> WithdrawalPeriodStandardValidation.validateDrugName(null));
        assertThrows(ServiceException.class, () -> WithdrawalPeriodStandardValidation.validateDrugName(""));
        assertDoesNotThrow(() -> WithdrawalPeriodStandardValidation.validateDrugName("阿"));
        assertDoesNotThrow(() -> WithdrawalPeriodStandardValidation.validateDrugName(repeat('a', 20)));
        assertThrows(ServiceException.class, () -> WithdrawalPeriodStandardValidation.validateDrugName(repeat('a', 21)));
    }

    @Test
    @DisplayName("药物类型 1～4")
    void drugType()
    {
        assertThrows(ServiceException.class, () -> WithdrawalPeriodStandardValidation.validateDrugType(null));
        assertThrows(ServiceException.class, () -> WithdrawalPeriodStandardValidation.validateDrugType(0));
        assertThrows(ServiceException.class, () -> WithdrawalPeriodStandardValidation.validateDrugType(5));
        assertDoesNotThrow(() -> WithdrawalPeriodStandardValidation.validateDrugType(1));
        assertDoesNotThrow(() -> WithdrawalPeriodStandardValidation.validateDrugType(4));
    }

    @Test
    @DisplayName("休药期 1～999")
    void withdrawalDays()
    {
        assertThrows(ServiceException.class, () -> WithdrawalPeriodStandardValidation.validateWithdrawalDays(null));
        assertThrows(ServiceException.class, () -> WithdrawalPeriodStandardValidation.validateWithdrawalDays(0));
        assertThrows(ServiceException.class, () -> WithdrawalPeriodStandardValidation.validateWithdrawalDays(1000));
        assertDoesNotThrow(() -> WithdrawalPeriodStandardValidation.validateWithdrawalDays(1));
        assertDoesNotThrow(() -> WithdrawalPeriodStandardValidation.validateWithdrawalDays(999));
    }

    @Test
    @DisplayName("使用指南/药物作用 1～200")
    void textFields()
    {
        assertThrows(ServiceException.class, () -> WithdrawalPeriodStandardValidation.validateUsageGuide(null));
        assertThrows(ServiceException.class, () -> WithdrawalPeriodStandardValidation.validateUsageGuide(repeat('测', 201)));
        assertDoesNotThrow(() -> WithdrawalPeriodStandardValidation.validateUsageGuide(repeat('测', 1)));
        assertDoesNotThrow(() -> WithdrawalPeriodStandardValidation.validateUsageGuide(repeat('测', 200)));

        assertThrows(ServiceException.class, () -> WithdrawalPeriodStandardValidation.validateDrugEffect(repeat('效', 201)));
        assertDoesNotThrow(() -> WithdrawalPeriodStandardValidation.validateDrugEffect(repeat('效', 200)));
    }

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