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

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

import java.math.BigDecimal;
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.dto.OpenYakEntryDto;
import com.ruoyi.web.modules.industryservice.domain.dto.YakAssetBundleDto;

@DisplayName("YakEntryOpenApiMapper")
class YakEntryOpenApiMapperTest
{
    @Test
    @DisplayName("OpenAPI 字段映射到 biz_yak_asset")
    void mapsOpenApiFields()
    {
        OpenYakEntryDto dto = new OpenYakEntryDto();
        dto.setCattleId(90001L);
        dto.setEarTagNumber("ET-001");
        dto.setCattleNo("CN-001");
        dto.setFarmId(1L);
        dto.setFarmName("示范牧场");
        dto.setFarmEnclosureId(201L);
        dto.setFarmEnclosureName("1号圈舍");
        dto.setBatchId(301L);
        dto.setEntryCycle("B2025-01");
        dto.setFarmLocation("东经91.0,北纬32.0");
        dto.setCattleSex("母");
        dto.setCattleSource("自繁");
        dto.setCattleVariety("牦牛");
        dto.setCattlePicture("https://example.com/cattle.jpg");
        dto.setRegistrant("张三");
        dto.setFatherNumber("F-01");
        dto.setMotherNumber("M-01");
        dto.setWeight(220.5);
        dto.setEntryTime("2023-08-01 10:00:00");
        dto.setBirthDate("2023-06-01");
        dto.setRemark("测试备注");

        YakAssetBundleDto bundle = YakEntryOpenApiMapper.toBundle(dto);
        BizYakAsset asset = bundle.getAsset();
        assertNotNull(asset);
        assertEquals(90001L, asset.getExternalId());
        assertEquals("CN-001", asset.getYakNo());
        assertEquals("ET-001", asset.getEarTagNumber());
        assertEquals(1L, asset.getFarmExternalId().longValue());
        assertEquals("示范牧场", asset.getPastureName());
        assertEquals(201L, asset.getEnclosureExternalId().longValue());
        assertEquals("B2025-01", asset.getEntryCycle());
        assertEquals(301L, asset.getBatchExternalId().longValue());
        assertEquals(null, asset.getBatchNo());
        assertEquals("母", asset.getGender());
        assertEquals("自繁", asset.getSource());
        assertEquals("1号圈舍", asset.getEnclosureName());
        assertEquals("1号圈舍", asset.getPenLocation());
        assertEquals("东经91.0,北纬32.0", asset.getLocation());
        assertEquals("牦牛", asset.getCattleVariety());
        assertEquals("https://example.com/cattle.jpg", asset.getCattlePicture());
        assertEquals("张三", asset.getRegistrant());
        assertEquals("F-01", asset.getFatherYakNo());
        assertEquals("M-01", asset.getMotherYakNo());
        assertEquals(new BigDecimal("220.5"), asset.getEntryWeightKg());
        assertEquals("测试备注", asset.getRemark());
        assertEquals("1", bundle.getThirdPartyPastureCode());
    }
}
