package com.ruoyi.app.omgpay;

import org.junit.jupiter.api.Test;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;

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

class OmgLegacyRetirementTest {
    @Test
    void oldRuntimeClassesAreAbsentAndNewControllerExposesSupportedPaymentOperations() {
        assertThrows(ClassNotFoundException.class, () -> Class.forName("com.ruoyi.app.pay.OmgPayController"));
        assertThrows(ClassNotFoundException.class, () -> Class.forName("com.ruoyi.app.task.OmgReconcileTask"));
        assertThrows(ClassNotFoundException.class, () -> Class.forName("com.ruoyi.system.domain.PosOrderOmgPayment"));
        assertThrows(ClassNotFoundException.class, () -> Class.forName("com.ruoyi.system.domain.PosOrderOmgRefund"));
        assertThrows(ClassNotFoundException.class, () -> Class.forName("com.ruoyi.app.utils.omg.OmgPay"));
        assertThrows(ClassNotFoundException.class, () -> Class.forName("com.ruoyi.app.utils.omg.OmgPayConfig"));
        assertThrows(ClassNotFoundException.class, () -> Class.forName("com.ruoyi.app.utils.omg.OmgCheckMacValue"));
        assertNotNull(OmgPaymentController.class.getAnnotation(RestController.class));
        Set<String> postPaths = Arrays.stream(OmgPaymentController.class.getDeclaredMethods())
                .filter(method -> method.isAnnotationPresent(PostMapping.class))
                .flatMap(method -> Arrays.stream(method.getAnnotation(PostMapping.class).value()))
                .collect(Collectors.toSet());
        assertEquals(Set.of("/create", "/notify", "/query", "/retry", "/refund"), postPaths);
        assertTrue(Arrays.stream(OmgPaymentController.class.getDeclaredMethods())
                .map(method -> method.getName().toLowerCase())
                .noneMatch(name -> name.contains("paymentinfo") || name.contains("return")));
    }
}
