package com.microservices.pms.productLibrary.controller;

import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.common.core.web.domain.GenericsAjaxResult;
import com.microservices.common.core.web.page.GenericsTableDataInfo;
import com.microservices.common.log.annotation.Log;
import com.microservices.common.log.enums.BusinessType;
import com.microservices.pms.productLibrary.domain.vo.*;
import com.microservices.pms.productLibrary.service.IPmsProductLibraryRepositoriesService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 制品库-仓库Controller
 *
 * @author otto
 * @date 2024-06-20
 */
@RestController
@Api(tags = "制品库-仓库相关接口")
@RequestMapping("/{enterpriseIdentifier}/pmsProductLibraryRepositories")
@ApiImplicitParams({
        @ApiImplicitParam(name = "enterpriseIdentifier", value = "组织标识", paramType = "path", dataType = "String")
})
public class PmsProductLibraryRepositoriesController extends BaseController {
    @Autowired
    private IPmsProductLibraryRepositoriesService pmsProductLibraryRepositoriesService;

    /**
     * 获取制品库锁定状态
     */
//    @RequiresPermissions("pms:pmsProductLibraryRepositories:list")
    @GetMapping("/lockStatus/{repoIds}")
    @ApiOperation(value = "获取锁定状态的制品库Id列表")
    public GenericsAjaxResult<List<Long>> getRepoLockStatus(@PathVariable String enterpriseIdentifier,
                                                            @ApiParam(value = "制品库Id列表(逗号分割)", required = true) @PathVariable String repoIds) {
        return GenericsAjaxResult.success(pmsProductLibraryRepositoriesService.getLockStatusRepositoryList(enterpriseIdentifier, repoIds));
    }

    /**
     * 查询制品库-仓库列表
     */
//    @RequiresPermissions("pms:pmsProductLibraryRepositories:list")
    @GetMapping("/byRepoName/{repoName}")
    @ApiOperation(value = "获取制品库详情")
    public GenericsAjaxResult<PmsProductLibraryRepositoriesDataVo> getByRepoName(@PathVariable String enterpriseIdentifier,
                                                                                 @ApiParam(value = "制品库标识", required = true) @PathVariable String repoName) {
        return GenericsAjaxResult.success(pmsProductLibraryRepositoriesService.selectPmsProductLibraryRepositoriesDataByName(enterpriseIdentifier, repoName));
    }

    /**
     * 查询制品库
     */
//    @RequiresPermissions("pms:pmsProductLibraryRepositories:list")
    @GetMapping("/list")
    @ApiOperation(value = "查询制品库列表")
    public GenericsTableDataInfo<PmsProductLibraryRepositoriesSimpleVo> list(
            @PathVariable String enterpriseIdentifier,
            @ApiParam("制品库搜索") PmsProductLibraryRepositoriesSearchVo searchVo) {
        startPage();
        return pmsProductLibraryRepositoriesService.selectPmsProductLibraryRepositoriesPageList(enterpriseIdentifier, searchVo);
    }

    /**
     * 新增制品库-仓库
     */
//    @RequiresPermissions("pms:pmsProductLibraryRepositories:add")
    @Log(title = "制品库-托管制品库", businessType = BusinessType.INSERT)
    @PostMapping("/hosted/{format}")
    @ApiOperation(value = "新增托管制品库")
    public AjaxResult addHosted(@PathVariable String enterpriseIdentifier,
                                @ApiParam(value = "制品库格式", required = true) @PathVariable String format,
                                @Valid @RequestBody HostedRepositoriesInputVo hostedPmsProductLibraryRepositoriesInputVo) {
        hostedPmsProductLibraryRepositoriesInputVo.setEnterpriseIdentifier(enterpriseIdentifier);
        hostedPmsProductLibraryRepositoriesInputVo.setFormat(format);
        return toAjax(pmsProductLibraryRepositoriesService.insertHostedPmsProductLibraryRepositories(hostedPmsProductLibraryRepositoriesInputVo));
    }

    /**
     *
     * 新增制品库-仓库
     */
//    @RequiresPermissions("pms:pmsProductLibraryRepositories:add")
    @Log(title = "制品库-虚拟仓库", businessType = BusinessType.INSERT)
    @PostMapping("/group/{format}")
    @ApiOperation(value = "新增虚拟仓库")
    public AjaxResult addGroup(@PathVariable String enterpriseIdentifier,
                               @ApiParam(value = "制品库格式", required = true) @PathVariable String format,
                               @Valid @RequestBody GroupRepositoriesInputVo groupRepositoriesInputVo) {
        groupRepositoriesInputVo.setEnterpriseIdentifier(enterpriseIdentifier);
        groupRepositoriesInputVo.setFormat(format);
        return toAjax(pmsProductLibraryRepositoriesService.insertGroupPmsProductLibraryRepositories(groupRepositoriesInputVo));
    }

    /**
     * 修改制品库-仓库
     */
//    @RequiresPermissions("pms:pmsProductLibraryRepositories:edit")
    @Log(title = "制品库-托管仓库", businessType = BusinessType.UPDATE)
    @PutMapping("/hosted/{format}/{name}")
    @ApiOperation(value = "更新托管仓库")
    public AjaxResult editHosted(@PathVariable String enterpriseIdentifier,
                                 @ApiParam(value = "制品库标识", required = true) @PathVariable String name,
                           @Valid @RequestBody HostedRepositoriesOperateVo hostedRepositoriesOperateVo) {
        hostedRepositoriesOperateVo.setEnterpriseIdentifier(enterpriseIdentifier);
        hostedRepositoriesOperateVo.setName(name);
        return toAjax(pmsProductLibraryRepositoriesService.updateHostedPmsProductLibraryRepositories(hostedRepositoriesOperateVo));
    }

    /**
     * 修改制品库-仓库
     */
//    @RequiresPermissions("pms:pmsProductLibraryRepositories:edit")
    @Log(title = "制品库-虚拟仓库", businessType = BusinessType.UPDATE)
    @PutMapping("/group/{format}/{name}")
    @ApiOperation(value = "更新虚拟仓库")
    public AjaxResult editGroup(@PathVariable String enterpriseIdentifier,
                                @ApiParam(value = "虚拟仓库标识", required = true) @PathVariable String name,
                                @Valid @RequestBody GroupRepositoriesOperateVo groupRepositoriesOperateVo) {
        groupRepositoriesOperateVo.setEnterpriseIdentifier(enterpriseIdentifier);
        groupRepositoriesOperateVo.setName(name);
        return toAjax(pmsProductLibraryRepositoriesService.updateGroupPmsProductLibraryRepositories(groupRepositoriesOperateVo));
    }

    /**
     * 删除制品库-仓库
     */
//    @RequiresPermissions("pms:pmsProductLibraryRepositories:remove")
    @Log(title = "制品库-仓库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{name}")
    @ApiOperation(value = "删除制品库")
    public AjaxResult remove(@PathVariable String enterpriseIdentifier,
                             @ApiParam(value = "制品库标识", required = true) @PathVariable String name) {
        return toAjax(pmsProductLibraryRepositoriesService.deletePmsProductLibraryRepositoriesByName(enterpriseIdentifier, name));
    }


    @GetMapping("/VersionPolicy/list")
    @ApiOperation(value = "版本策略列表")
    public List<CommonTypeVo> versionPolicyList() {
        return pmsProductLibraryRepositoriesService.selectVersionPolicyList();
    }

    @GetMapping("/LayoutPolicy/list")
    @ApiOperation(value = "布局策略列表")
    public List<CommonTypeVo> layoutPolicyList() {
        return pmsProductLibraryRepositoriesService.selectLayoutPolicyList();
    }

    @GetMapping("/Format/list")
    @ApiOperation(value = "制品库格式列表")
    public List<CommonTypeVo> formatList() {
        return pmsProductLibraryRepositoriesService.selectFormatList();
    }

    @GetMapping("/Type/list")
    @ApiOperation(value = "制品库类型列表")
    public List<CommonTypeVo> typeList() {
        return pmsProductLibraryRepositoriesService.selectTypeList();
    }
}
