package com.njcn.gather.event.eventlist.service.impl;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.njcn.gather.event.eventlist.pojo.param.EventListQueryParam;
import com.njcn.gather.event.eventlist.pojo.vo.EventListVO;
import org.junit.Test;

import java.lang.reflect.Method;
import java.time.LocalDateTime;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class EventListTimeFormatTest {

    @Test
    public void startTimeJsonKeepsMilliseconds() throws Exception {
        EventListVO vo = new EventListVO();
        vo.setStartTime(LocalDateTime.of(2026, 5, 10, 13, 41, 17, 944000000));

        String json = new ObjectMapper().writeValueAsString(vo);

        assertTrue(json.contains("\"startTime\":\"2026-05-10 13:41:17.944\""));
    }

    @Test
    public void queryTimeNormalizationKeepsMilliseconds() throws Exception {
        EventListQueryParam param = new EventListQueryParam();
        param.setStartTimeStart("2026-05-10 13:41:17.944");
        param.setStartTimeEnd("2026-05-10 13:41:18.123");

        normalizeQueryParam(param);

        assertEquals("2026-05-10 13:41:17.944", param.getStartTimeStart());
        assertEquals("2026-05-10 13:41:18.123", param.getStartTimeEnd());
    }

    private void normalizeQueryParam(EventListQueryParam param) throws Exception {
        EventListServiceImpl service = new EventListServiceImpl(null, null, null, null, null, null);
        Method method = EventListServiceImpl.class.getDeclaredMethod("normalizeQueryParam", EventListQueryParam.class);
        method.setAccessible(true);
        method.invoke(service, param);
    }
}
