package com.ruoyi.ccdi.project.controller;

import com.ruoyi.ccdi.project.domain.dto.CcdiRelationGraphQueryDTO;
import com.ruoyi.ccdi.project.domain.dto.CcdiRelationGraphSuspectedEnterpriseQueryDTO;
import com.ruoyi.ccdi.project.domain.vo.CcdiRelationGraphNodeVO;
import com.ruoyi.ccdi.project.domain.vo.CcdiRelationGraphSuspectedEnterpriseVO;
import com.ruoyi.ccdi.project.domain.vo.CcdiRelationGraphVO;
import com.ruoyi.ccdi.project.service.CcdiProjectAccessService;
import com.ruoyi.ccdi.project.service.ICcdiRelationGraphService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 关系图谱Controller
 */
@RestController
@RequestMapping("/ccdi/project/relation-graph")
@Tag(name = "关系图谱")
public class CcdiRelationGraphController extends BaseController {

    @Resource
    private ICcdiRelationGraphService relationGraphService;

    @Resource
    private CcdiProjectAccessService projectAccessService;

    @GetMapping("/search")
    @Operation(summary = "查询关系图谱主体")
    @PreAuthorize("@ss.hasPermi('ccdi:project:query')")
    public AjaxResult searchSubjects(CcdiRelationGraphQueryDTO queryDTO) {
        projectAccessService.assertCanRead(queryDTO.getProjectId());
        List<CcdiRelationGraphNodeVO> subjects = relationGraphService.searchSubjects(queryDTO);
        return AjaxResult.success(subjects);
    }

    @GetMapping("/graph")
    @Operation(summary = "查询一层关系图谱")
    @PreAuthorize("@ss.hasPermi('ccdi:project:query')")
    public AjaxResult getGraph(CcdiRelationGraphQueryDTO queryDTO) {
        projectAccessService.assertCanRead(queryDTO.getProjectId());
        CcdiRelationGraphVO graph = relationGraphService.getRelationGraph(queryDTO);
        return AjaxResult.success(graph);
    }

    @GetMapping("/suspected-enterprises")
    @Operation(summary = "查询关系图谱疑似同名企业")
    @PreAuthorize("@ss.hasPermi('ccdi:project:query')")
    public AjaxResult getSuspectedEnterprises(CcdiRelationGraphSuspectedEnterpriseQueryDTO queryDTO) {
        projectAccessService.assertCanRead(queryDTO.getProjectId());
        CcdiRelationGraphSuspectedEnterpriseVO result = relationGraphService.getSuspectedEnterprises(queryDTO);
        return AjaxResult.success(result);
    }
}
