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

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

import java.math.BigDecimal;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.web.modules.epidemic.RiskFactorWeightTestSamples;
import com.ruoyi.web.modules.epidemic.domain.dto.RiskFactorWeightSaveRequest;

/**
 * FXYZ-UT-002、006
 */
@DisplayName("RiskFactorWeightValidation")
class RiskFactorWeightValidationTest
{

    @Test
    @DisplayName("FXYZ-UT-002 五项必填")
    void ut002_required()
    {
        RiskFactorWeightSaveRequest req = RiskFactorWeightTestSamples.uniformRequest();
        req.setPastDiseaseLevelWeight(null);
        assertThrows(ServiceException.class, () -> RiskFactorWeightValidation.validateForSave(req));
    }

    @Test
    @DisplayName("合法保存校验")
    void validSave()
    {
        assertDoesNotThrow(() -> RiskFactorWeightValidation.validateForSave(RiskFactorWeightTestSamples.uniformRequest()));
    }

    @Test
    @DisplayName("FXYZ-UT-006 合计不为 1 提示含当前合计")
    void ut006_sumErrorMessage()
    {
        RiskFactorWeightSaveRequest req = RiskFactorWeightTestSamples.uniformRequest();
        req.setBreedingDensityWeight(new BigDecimal("0.3"));
        ServiceException ex = assertThrows(ServiceException.class, () -> RiskFactorWeightValidation.validateForSave(req));
        assertEquals(true, ex.getMessage().contains("当前合计"));
    }

    @Test
    @DisplayName("toVo 含 weightSum")
    void toVoWeightSum()
    {
        com.ruoyi.web.modules.epidemic.domain.vo.RiskFactorWeightVo vo =
                RiskFactorWeightValidation.toVo(RiskFactorWeightTestSamples.dbRow());
        assertEquals(new BigDecimal("1.0000"), vo.getWeightSum());
        assertEquals(new BigDecimal("0.2000"), vo.getBreedingDensityWeight());
    }
}
