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

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

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import com.ruoyi.web.modules.industryservice.domain.BizYakHealthSourceRecord;
import com.ruoyi.web.modules.industryservice.domain.dto.OpenDiagnosisRecordDto;
import com.ruoyi.web.modules.industryservice.domain.dto.OpenQuarantineRecordDto;

@DisplayName("HealthRecordOpenApiMapper")
class HealthRecordOpenApiMapperTest
{
    @Test
    @DisplayName("检疫记录映射 external_id 与牧场地区键")
    void fromQuarantine()
    {
        OpenQuarantineRecordDto dto = new OpenQuarantineRecordDto();
        dto.setId(100L);
        dto.setFarmId(1L);
        dto.setFarmName("示范牧场");
        dto.setFarmEnclosureId(101L);
        dto.setCattleId(5001L);
        dto.setEarTagNumber("YAK-001");
        dto.setQuarantineTime("2026-05-19 10:00:00");
        dto.setQuarantineResult("阳性");

        BizYakHealthSourceRecord row = HealthRecordOpenApiMapper.fromQuarantine(dto);
        assertEquals("Q:100", row.getExternalId());
        assertEquals(YakDiseaseWarningAnalysisRules.RECORD_TYPE_QUARANTINE, row.getRecordType().intValue());
        assertEquals("YAK-001", row.getYakNo());
        assertEquals("阳性", row.getQuarantineResult());
        assertEquals("F:1", row.getRegionKey());
        assertEquals(YakDiseaseWarningAnalysisRules.ANALYZED_NO, row.getAnalyzedFlag());
    }

    @Test
    @DisplayName("诊疗记录映射 cattleId 为 yak_no")
    void fromDiagnosis()
    {
        OpenDiagnosisRecordDto dto = new OpenDiagnosisRecordDto();
        dto.setId(200L);
        dto.setFarmId(2L);
        dto.setCattleId(6001L);
        dto.setDiagnosisTime("2026-05-18 09:00:00");
        dto.setDiagnosisResult("发热");

        BizYakHealthSourceRecord row = HealthRecordOpenApiMapper.fromDiagnosis(dto);
        assertEquals("D:200", row.getExternalId());
        assertEquals("6001", row.getYakNo());
        assertEquals("发热", row.getDiagnosisResult());
        assertEquals("F:2", row.getRegionKey());
        assertNotNull(row.getRecordTime());
    }
}
