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

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.time.LocalDate;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.web.modules.booking.domain.AppBookingSubmitBody;
import com.ruoyi.web.modules.booking.domain.vo.AppointmentResourceVo;

@DisplayName("AppBookingSubmitValidation")
class AppBookingSubmitValidationTest
{

    @Test
    @DisplayName("解析时段")
    void parseTimeSlot()
    {
        AppBookingSubmitBody body = sampleBody();
        body.setTimeSlot("08:00~10:00");
        AppBookingSubmitValidation.validateBody(body);
        assertEquals("08:00", body.getTimeStart());
        assertEquals("10:00", body.getTimeEnd());
    }

    @Test
    @DisplayName("服务日不匹配")
    void weekdayMismatch()
    {
        AppointmentResourceVo resource = new AppointmentResourceVo();
        resource.setServiceWeekdays("2,3,4,5,6");
        assertThrows(ServiceException.class, () -> AppBookingSubmitValidation.assertServiceWeekdayAllowed(resource,
                LocalDate.of(2026, 5, 24)));
    }

    private static AppBookingSubmitBody sampleBody()
    {
        AppBookingSubmitBody body = new AppBookingSubmitBody();
        body.setResourceType(AppointmentResourceRules.TYPE_VET);
        body.setResourceId(1L);
        body.setAppointDate("2026-05-20");
        body.setAppointeeName("扎西");
        body.setContactPhone("13800138000");
        body.setServiceAddress("巴青县");
        return body;
    }
}
