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

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

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

@DisplayName("VetAppointmentValidation")
class VetAppointmentValidationTest
{
    @Test
    @DisplayName("拒绝理由空/空白")
    void rejectReasonEmpty()
    {
        assertThrows(ServiceException.class, () -> VetAppointmentValidation.validateRejectReason(null));
        assertThrows(ServiceException.class, () -> VetAppointmentValidation.validateRejectReason(""));
        assertThrows(ServiceException.class, () -> VetAppointmentValidation.validateRejectReason("   "));
    }

    @Test
    @DisplayName("拒绝理由长度")
    void rejectReasonLength()
    {
        assertDoesNotThrow(() -> VetAppointmentValidation.validateRejectReason("a"));
        String hundred = repeat('x', 100);
        assertDoesNotThrow(() -> VetAppointmentValidation.validateRejectReason(hundred));
        assertThrows(ServiceException.class,
                () -> VetAppointmentValidation.validateRejectReason(repeat('x', 101)));
    }

    @Test
    @DisplayName("预约日期区间")
    void dateRange()
    {
        BizServiceAppointment q = new BizServiceAppointment();
        q.setStartDate("2026-05-20");
        q.setEndDate("2026-05-10");
        assertThrows(ServiceException.class, () -> VetAppointmentValidation.validateListQuery(q));
        q.setEndDate("2026-05-20");
        assertDoesNotThrow(() -> VetAppointmentValidation.validateListQuery(q));
    }

    @Test
    @DisplayName("状态筛选非法")
    void invalidStatus()
    {
        BizServiceAppointment q = new BizServiceAppointment();
        q.setStatus(5);
        assertThrows(ServiceException.class, () -> VetAppointmentValidation.validateListQuery(q));
    }

    @Test
    @DisplayName("trim 拒绝理由")
    void trimRejectReason()
    {
        assertEquals("理由", VetAppointmentValidation.trimRejectReason("  理由  "));
    }

    private static String repeat(char c, int n)
    {
        StringBuilder sb = new StringBuilder(n);
        for (int i = 0; i < n; i++)
        {
            sb.append(c);
        }
        return sb.toString();
    }
}
