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

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.math.BigDecimal;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import com.ruoyi.web.modules.industryservice.domain.BizFarmerHousehold;

@DisplayName("FarmerHouseholdDerivedSupport 草畜失衡判定")
class FarmerHouseholdDerivedSupportImbalanceTest
{
    @Test
    @DisplayName("核定载畜量 < 年底存栏 → 失衡")
    void imbalancedWhenCapacityLessThanStock()
    {
        BizFarmerHousehold row = row("100", "120");
        assertTrue(FarmerHouseholdDerivedSupport.isImbalanced(row));
    }

    @Test
    @DisplayName("核定载畜量 = 年底存栏 → 已平衡（预警应消失）")
    void balancedWhenEqual()
    {
        BizFarmerHousehold row = row("100", "100");
        assertFalse(FarmerHouseholdDerivedSupport.isImbalanced(row));
    }

    @Test
    @DisplayName("核定载畜量 > 年底存栏 → 已平衡（预警应消失）")
    void balancedWhenCapacityGreater()
    {
        BizFarmerHousehold row = row("120", "100");
        assertFalse(FarmerHouseholdDerivedSupport.isImbalanced(row));
    }

    @Test
    @DisplayName("任一字段为空 → 不触发失衡")
    void notImbalancedWhenNull()
    {
        BizFarmerHousehold row = row("100", null);
        assertFalse(FarmerHouseholdDerivedSupport.isImbalanced(row));
        row = row(null, "100");
        assertFalse(FarmerHouseholdDerivedSupport.isImbalanced(row));
    }

    private static BizFarmerHousehold row(String capacity, String stock)
    {
        BizFarmerHousehold row = new BizFarmerHousehold();
        row.setApprovedCarryingCapacity(capacity == null ? null : new BigDecimal(capacity));
        row.setYearEndStockSheepUnit(stock == null ? null : new BigDecimal(stock));
        return row;
    }
}
