package com.aps.demo;

import com.aps.service.plan.PlanResultService;
import org.junit.jupiter.api.Test;
import org.springframework.test.util.ReflectionTestUtils;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

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

class AutoInsertPayloadTest {

    @Test
    void autoInsertPayloadSupportsFrontendDateAndPriorityAliases() {
        PlanResultService service = new PlanResultService();
        Map<String, Object> payload = new HashMap<>();
        payload.put("begintime", "2026-07-01T00:00:00.000Z");
        payload.put("deliverytime", "2026-07-31T00:00:00.000Z");
        payload.put("prioritry", "3");

        String startText = ReflectionTestUtils.invokeMethod(
                service, "getFirstStringValue", payload, new String[]{"startDate", "begintime", "beginTime"});
        String endText = ReflectionTestUtils.invokeMethod(
                service, "getFirstStringValue", payload, new String[]{"endDate", "deliverytime", "deliveryTime"});
        String priorityText = ReflectionTestUtils.invokeMethod(
                service, "getFirstStringValue", payload, new String[]{"priority", "prioritry"});

        LocalDateTime start = ReflectionTestUtils.invokeMethod(service, "parseOrderDateTime", startText);
        LocalDateTime end = ReflectionTestUtils.invokeMethod(service, "parseOrderDateTime", endText);
        Integer priority = ReflectionTestUtils.invokeMethod(service, "parseOrderPriority", priorityText);

        assertEquals(LocalDateTime.of(2026, 7, 1, 0, 0), start);
        assertEquals(LocalDateTime.of(2026, 7, 31, 0, 0), end);
        assertEquals(Integer.valueOf(3), priority);
    }
}
