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

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

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import com.ruoyi.web.modules.industryservice.domain.BizPasture;
import com.ruoyi.web.modules.industryservice.domain.BizYakAsset;
import com.ruoyi.web.modules.industryservice.research.domain.vo.ResearchPastureVo;
import com.ruoyi.web.modules.industryservice.research.domain.vo.ResearchYakAssetVo;

@DisplayName("科研开放接口脱敏")
class ResearchOpenApiMaskingTest
{
    @Test
    @DisplayName("手机号与负责人脱敏")
    void maskContact()
    {
        assertEquals("138****5678", ResearchOpenApiMasking.maskPhone("13812345678"));
        assertEquals("张*", ResearchOpenApiMasking.maskPersonName("张三"));
    }

    @Test
    @DisplayName("牧场 VO 不含详细地址与第三方编号")
    void pastureVo()
    {
        BizPasture row = new BizPasture();
        row.setId(101L);
        row.setExternalId(999L);
        row.setPastureName("测试牧场");
        row.setCounty("巴青县");
        row.setTown("北拉镇");
        row.setDetailAddress("某村1号");
        row.setPersonInCharge("扎西");
        row.setContactPhone("13900001111");
        row.setLatitude(31.123456);
        row.setLongitude(93.987654);

        ResearchPastureVo vo = ResearchOpenApiSupport.toPastureVo(row);
        assertEquals(101L, vo.getPastureId());
        assertEquals("巴青县 北拉镇", vo.getRegionSummary());
        assertEquals("扎*", vo.getPersonInCharge());
        assertEquals("139****1111", vo.getContactPhone());
        assertEquals(31.123, vo.getLatitude(), 0.0001);
    }

    @Test
    @DisplayName("牦牛档案 VO 使用 subjectCode 替代明文编号")
    void yakAssetVo()
    {
        BizYakAsset row = new BizYakAsset();
        row.setId(88L);
        row.setYakNo("YAK-REAL-001");
        row.setEarTagNumber("ET123456");
        row.setGender("母");
        row.setFatherYakNo("F-001");
        row.setMotherYakNo("M-002");
        row.setPastureName("测试牧场");

        ResearchYakAssetVo vo = ResearchOpenApiSupport.toYakAssetVo(row);
        assertEquals("YS00000088", vo.getSubjectCode());
        assertNotNull(vo.getFatherSubjectCode());
        assertNotNull(vo.getMotherSubjectCode());
        assertTrue(vo.getFatherSubjectCode().startsWith("YP"));
    }
}
