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.BizFamilyRanch;

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

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

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

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

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