package com.yhy.module.core.controller.admin.config;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import com.yhy.module.core.controller.admin.config.vo.ConfigProjectInfoRespVO;
import com.yhy.module.core.controller.admin.config.vo.ConfigProjectInfoSaveReqVO;
import com.yhy.module.core.controller.admin.config.vo.ConfigProjectInfoSwapSortReqVO;
import com.yhy.module.core.service.config.ConfigProjectInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import javax.annotation.Resource;
import javax.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 工程信息配置 Controller
 *
 * @author yhy
 */
@Tag(name = "管理后台 - 工程信息配置")
@RestController
@RequestMapping("/core/config/project-info")
@Validated
public class ConfigProjectInfoController {

    @Resource
    private ConfigProjectInfoService configProjectInfoService;

    @PostMapping("/create")
    @Operation(summary = "创建工程信息配置")
    @PreAuthorize("@ss.hasPermission('core:config-project-info:create')")
    public CommonResult<Long> createConfigProjectInfo(@Valid @RequestBody ConfigProjectInfoSaveReqVO createReqVO) {
        return success(configProjectInfoService.createConfigProjectInfo(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新工程信息配置")
    @PreAuthorize("@ss.hasPermission('core:config-project-info:update')")
    public CommonResult<Boolean> updateConfigProjectInfo(@Valid @RequestBody ConfigProjectInfoSaveReqVO updateReqVO) {
        configProjectInfoService.updateConfigProjectInfo(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除工程信息配置")
    @Parameter(name = "id", description = "ID", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('core:config-project-info:delete')")
    public CommonResult<Boolean> deleteConfigProjectInfo(@RequestParam("id") Long id) {
        configProjectInfoService.deleteConfigProjectInfo(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获取工程信息配置详情")
    @Parameter(name = "id", description = "ID", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('core:config-project-info:query')")
    public CommonResult<ConfigProjectInfoRespVO> getConfigProjectInfo(@RequestParam("id") Long id) {
        return success(configProjectInfoService.getConfigProjectInfo(id));
    }

    @GetMapping("/tree")
    @Operation(summary = "获取工程信息配置树（按行业节点）")
    @Parameter(name = "configTreeId", description = "行业节点ID", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('core:config-project-info:query')")
    public CommonResult<List<ConfigProjectInfoRespVO>> getConfigProjectInfoTree(
            @RequestParam("configTreeId") Long configTreeId) {
        return success(configProjectInfoService.getConfigProjectInfoTree(configTreeId));
    }

    @PostMapping("/swap-sort")
    @Operation(summary = "交换排序")
    @PreAuthorize("@ss.hasPermission('core:config-project-info:update')")
    public CommonResult<Boolean> swapSort(@Valid @RequestBody ConfigProjectInfoSwapSortReqVO swapReqVO) {
        configProjectInfoService.swapSort(swapReqVO);
        return success(true);
    }
}
