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

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.math.BigDecimal;
import java.util.Collections;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import com.ruoyi.web.modules.industryservice.domain.BizYakAsset;
import com.ruoyi.web.modules.industryservice.domain.BizYakGrowthRecord;
import com.ruoyi.web.modules.industryservice.domain.dto.OpenWeighingDto;
import com.ruoyi.web.modules.industryservice.domain.vo.YakAssetGrowthChartVo;

@DisplayName("YakAssetGrowthSupport")
class YakAssetGrowthSupportTest
{
    @Test
    @DisplayName("称重 cattleId 参数取 external_id")
    void resolveWeighingCattleIdParam()
    {
        BizYakAsset asset = new BizYakAsset();
        asset.setExternalId(4001L);
        assertEquals(4001L, YakAssetGrowthSupport.resolveWeighingCattleIdParam(asset));
    }

    @Test
    @DisplayName("称重转生长记录仅填体重与采集时间")
    void toGrowthRecords()
    {
        OpenWeighingDto dto = new OpenWeighingDto();
        dto.setWeight("385.50");
        dto.setWeighingTime("2026-05-20 08:30:00");
        BizYakGrowthRecord row = YakAssetGrowthSupport.toGrowthRecords(Collections.singletonList(dto)).get(0);
        assertEquals(new BigDecimal("385.50"), row.getWeightKg());
        assertNull(row.getDayAge());
        assertNull(row.getHeightCm());
        assertNull(row.getChestCm());
        assertNull(row.getLengthCm());
        assertEquals(YakAssetRules.DATA_KIND_ACTUAL, row.getDataKind());
    }

    @Test
    @DisplayName("体高指标从生长记录组装曲线")
    void toGrowthChartHeight()
    {
        BizYakGrowthRecord row = new BizYakGrowthRecord();
        row.setDayAge(120);
        row.setHeightCm(new BigDecimal("95"));
        row.setDataKind(YakAssetRules.DATA_KIND_ACTUAL);
        YakAssetGrowthChartVo chart = YakAssetGrowthSupport.toGrowthChart(Collections.singletonList(row), "height");
        assertEquals(1, chart.getActual().size());
        assertEquals(new BigDecimal("95"), chart.getActual().get(0).getValue());
    }

    @Test
    @DisplayName("体高指标无数据时曲线为空")
    void toGrowthChartHeightEmpty()
    {
        BizYakGrowthRecord row = new BizYakGrowthRecord();
        row.setWeightKg(new BigDecimal("200"));
        YakAssetGrowthChartVo chart = YakAssetGrowthSupport.toGrowthChart(Collections.singletonList(row), "height");
        assertEquals(0, chart.getActual().size());
    }
}
