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

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.workbench.vo.WbItemInfoRespVO;
import com.yhy.module.core.controller.admin.workbench.vo.WbItemInfoSaveReqVO;
import com.yhy.module.core.service.workbench.WbItemInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
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.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
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/wb/item-info")
@Validated
public class WbItemInfoController {

    @Resource
    private WbItemInfoService wbItemInfoService;

    @GetMapping("/get")
    @Operation(summary = "获取单项基本信息")
    @Parameter(name = "compileTreeId", description = "编制树节点ID（单项节点）", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('core:wb-item-info:query')")
    public CommonResult<WbItemInfoRespVO> get(@RequestParam("compileTreeId") Long compileTreeId) {
        return success(wbItemInfoService.getByCompileTreeId(compileTreeId));
    }

    @PostMapping("/save")
    @Operation(summary = "保存单项基本信息")
    @PreAuthorize("@ss.hasPermission('core:wb-item-info:update')")
    public CommonResult<Long> save(@Valid @RequestBody WbItemInfoSaveReqVO saveReqVO) {
        return success(wbItemInfoService.save(saveReqVO));
    }

    @PostMapping("/refresh-config")
    @Operation(summary = "刷新配置快照")
    @Parameter(name = "compileTreeId", description = "编制树节点ID（单项节点）", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('core:wb-item-info:update')")
    public CommonResult<Boolean> refreshConfigSnapshot(@RequestParam("compileTreeId") Long compileTreeId) {
        wbItemInfoService.refreshConfigSnapshot(compileTreeId);
        return success(true);
    }
}
