package com.ruoyi.ccdi.project.controller;

import com.ruoyi.ccdi.project.domain.dto.CcdiProjectImportHistoryDTO;
import com.ruoyi.ccdi.project.domain.dto.CcdiProjectQueryDTO;
import io.swagger.v3.oas.annotations.Operation;
import org.junit.jupiter.api.Test;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.lang.reflect.Method;

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

class CcdiProjectControllerContractTest {

    @Test
    void shouldExposeArchiveProjectEndpointContract() throws Exception {
        RequestMapping requestMapping = CcdiProjectController.class.getAnnotation(RequestMapping.class);
        Method method = CcdiProjectController.class.getMethod("archiveProject", Long.class);
        PostMapping postMapping = method.getAnnotation(PostMapping.class);
        PreAuthorize preAuthorize = method.getAnnotation(PreAuthorize.class);
        Operation operation = method.getAnnotation(Operation.class);

        assertNotNull(requestMapping);
        assertEquals("/ccdi/project", requestMapping.value()[0]);
        assertNotNull(postMapping);
        assertEquals("/{projectId}/archive", postMapping.value()[0]);
        assertNotNull(preAuthorize);
        assertEquals("@ss.hasPermi('ccdi:project:edit')", preAuthorize.value());
        assertNotNull(operation);
        assertEquals("归档项目", operation.summary());
    }

    @Test
    void shouldExposeHistoryImportEndpointContracts() throws Exception {
        Method history = CcdiProjectController.class.getMethod("listHistoryProjects", CcdiProjectQueryDTO.class);
        GetMapping historyMapping = history.getAnnotation(GetMapping.class);
        assertNotNull(historyMapping);
        assertEquals("/history", historyMapping.value()[0]);

        Method importing = CcdiProjectController.class.getMethod("importFromHistory", CcdiProjectImportHistoryDTO.class);
        PostMapping importMapping = importing.getAnnotation(PostMapping.class);
        assertNotNull(importMapping);
        assertEquals("/import", importMapping.value()[0]);
    }
}
