package com.ruoyi.web.modules.industryservice.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.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.web.modules.industryservice.domain.BizYakDiseaseWarning;

@DisplayName("YakDiseaseWarningValidation")
class YakDiseaseWarningValidationTest
{
    @Test
    @DisplayName("ZCZX-MYNBJY-UT-001 开始晚于结束")
    void ut001_dateRangeInvalid()
    {
        BizYakDiseaseWarning q = new BizYakDiseaseWarning();
        q.setStartDate("2026-05-10");
        q.setEndDate("2026-05-01");
        ServiceException ex = assertThrows(ServiceException.class, () -> YakDiseaseWarningValidation.applyDateRange(q));
        assertEquals(YakDiseaseWarningRules.MSG_DATE_RANGE_INVALID, ex.getMessage());
    }

    @Test
    @DisplayName("ZCZX-MYNBJY-UT-002 仅开始日期")
    void ut002_startOnly()
    {
        BizYakDiseaseWarning q = new BizYakDiseaseWarning();
        q.setStartDate("2026-05-01");
        YakDiseaseWarningValidation.applyDateRange(q);
        assertNotNull(q.getAlertTimeBegin());
        assertNotNull(q.getAlertTimeEnd());
    }

    @Test
    @DisplayName("ZCZX-MYNBJY-UT-003 仅结束日期")
    void ut003_endOnly()
    {
        BizYakDiseaseWarning q = new BizYakDiseaseWarning();
        q.setEndDate("2026-04-30");
        YakDiseaseWarningValidation.applyDateRange(q);
        assertNull(q.getAlertTimeBegin());
        assertNotNull(q.getAlertTimeEnd());
    }

    @Test
    @DisplayName("ZCZX-MYNBJY-UT-004 起止均为空")
    void ut004_noDateFilter()
    {
        BizYakDiseaseWarning q = new BizYakDiseaseWarning();
        YakDiseaseWarningValidation.applyDateRange(q);
        assertNull(q.getAlertTimeBegin());
        assertNull(q.getAlertTimeEnd());
    }

    @Test
    @DisplayName("ZCZX-MYNBJY-UT-007 体温文案拼接")
    void ut007_buildTempMessage()
    {
        String msg = YakDiseaseWarningValidation.buildAlertMessage(YakDiseaseWarningRules.WARNING_TYPE_TEMP, "39.8℃",
                "正常体温参考范围", null);
        assertTrue(msg.contains("39.8℃"));
        assertTrue(msg.contains("体温异常"));
    }

    @Test
    @DisplayName("ZCZX-MYNBJY-UT-005 预警类型含检疫/诊疗")
    void ut005_warningTypes()
    {
        assertTrue(YakDiseaseWarningRules.isValidWarningType(YakDiseaseWarningRules.WARNING_TYPE_QUARANTINE));
        assertTrue(YakDiseaseWarningRules.isValidWarningType(YakDiseaseWarningRules.WARNING_TYPE_DIAGNOSIS));
    }

    @Test
    @DisplayName("检疫集中预警文案")
    void buildQuarantineMessage()
    {
        String msg = YakDiseaseWarningValidation.buildAlertMessage(YakDiseaseWarningRules.WARNING_TYPE_QUARANTINE,
                null, null, "2026-05-19 巴青县 地区检疫结果异常或阳性记录集中（3条），触发健康预警。");
        assertTrue(msg.contains("检疫"));
        assertTrue(msg.contains("健康预警"));
    }
}
