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

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
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.industryservice.domain.dto.GrassLivestockBalanceCalculateRequest;

@DisplayName("GrassLivestockBalanceValidation")
class GrassLivestockBalanceValidationTest
{
    @Test
    @DisplayName("ZCZX-CXPH-UT-008 面积与利用率")
    void ut008_areaAndUtilization()
    {
        assertThrows(ServiceException.class, () -> GrassLivestockBalanceValidation.validateAreaMu(BigDecimal.ZERO));
        assertThrows(ServiceException.class,
                () -> GrassLivestockBalanceValidation.validateUtilizationRate(new BigDecimal("1.1")));
        assertDoesNotThrow(() -> GrassLivestockBalanceValidation.validateUtilizationRate(new BigDecimal("0.65")));
    }

    @Test
    @DisplayName("ZCZX-CXPH-UT-009 羊单位参数")
    void ut009_sheepUnitParams()
    {
        assertThrows(ServiceException.class,
                () -> GrassLivestockBalanceValidation.validatePositive(BigDecimal.ZERO, "羊单位年需草量须大于0"));
        assertThrows(ServiceException.class,
                () -> GrassLivestockBalanceValidation.validatePositive(null, "羊单位折算系数须大于0"));
    }

    @Test
    @DisplayName("ZCZX-CXPH-UT-010 养殖数量")
    void ut010_breedingHeadCount()
    {
        assertThrows(ServiceException.class, () -> GrassLivestockBalanceValidation.validateBreedingHeadCount(-1));
        assertDoesNotThrow(() -> GrassLivestockBalanceValidation.validateBreedingHeadCount(0));
    }

    @Test
    @DisplayName("ZCZX-CXPH-UT-011 缺草场id")
    void ut011_grasslandId()
    {
        GrassLivestockBalanceCalculateRequest req = validRequest();
        req.setGrasslandId(null);
        assertThrows(ServiceException.class, () -> GrassLivestockBalanceValidation.validateCalculateRequest(req));
    }

    private static GrassLivestockBalanceCalculateRequest validRequest()
    {
        GrassLivestockBalanceCalculateRequest req = new GrassLivestockBalanceCalculateRequest();
        req.setGrasslandId(1L);
        req.setAreaMu(new BigDecimal("100"));
        req.setGrassYieldPerMu(new BigDecimal("350"));
        req.setUtilizationRate(new BigDecimal("0.65"));
        req.setSheepUnitAnnualForageKg(new BigDecimal("160"));
        req.setSheepUnitConvertCoeff(new BigDecimal("4"));
        req.setBreedingHeadCount(10);
        return req;
    }
}
