package com.microservices.pms.project.controller;


import com.alibaba.fastjson2.JSONObject;
import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.common.security.annotation.Logical;
import com.microservices.common.security.annotation.RequiresPermissions;
import com.microservices.pms.project.domain.vo.PmsProjectRepositorySearchVo;
import com.microservices.pms.project.domain.vo.PmsProjectUnlinkedRepositorySearchVo;
import com.microservices.pms.project.service.IPmsProjectRepositoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 项目-代码库Controller
 * 
 * @author wanjia
 * @date 2023-10-11
 */
@RestController
@RequestMapping("/{enterpriseIdentifier}/pmsProjectRepository")
@Api(tags = "项目管理-项目仓库接口")
@ApiImplicitParams({
        @ApiImplicitParam(name = "enterpriseIdentifier", value = "企业标识", paramType = "path", dataType = "String")
})
public class PmsProjectRepositoryController extends BaseController
{
    @Autowired
    private IPmsProjectRepositoryService pmsProjectRepositoryService;

    /**
     * 查询项目-代码库列表
     */
    @RequiresPermissions(value = {"pms:pmsProject:show", "pms:pmsProject:showMe"}, logical = Logical.OR)
    @GetMapping("/list")
    public AjaxResult list(@Validated PmsProjectRepositorySearchVo pmsProjectRepositorySearchVo)
    {
        JSONObject result = pmsProjectRepositoryService.selectPmsProjectRepositoryList(pmsProjectRepositorySearchVo);
        return success(result);
    }


    /**
     * 查询企业下未被项目关联的代码库列表
     */
    @RequiresPermissions(value = {"pms:pmsProject:show", "pms:pmsProject:showMe"}, logical = Logical.OR)
    @GetMapping("/list/unlinked")
    public AjaxResult unlinkedList(@Validated PmsProjectUnlinkedRepositorySearchVo pmsProjectUnlinkedRepositorySearchVo)
    {
        JSONObject result = pmsProjectRepositoryService.selectUnlinkedPmsRepositoryListByEnterpriseIdentifier(pmsProjectUnlinkedRepositorySearchVo);
        return success(result);
    }


    /**
     * 获取项目-代码库详细信息
     */
    @RequiresPermissions(value = {"pms:pmsProject:show", "pms:pmsProject:showMe"}, logical = Logical.OR)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pmsProjectRepositoryService.selectPmsProjectRepositoryById(id));
    }
}
