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.WbBoqMarketMaterialRespVO;
import com.yhy.module.core.controller.admin.workbench.vo.WbBoqMarketMaterialSaveReqVO;
import com.yhy.module.core.service.workbench.WbBoqMarketMaterialService;
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/wb/boq-market-material")
@Validated
public class WbBoqMarketMaterialController {

    @Resource
    private WbBoqMarketMaterialService wbBoqMarketMaterialService;

    @PostMapping("/create")
    @Operation(summary = "创建市场主材设备")
    @PreAuthorize("@ss.hasPermission('core:wb-boq-division:create')")
    public CommonResult<Long> createMarketMaterial(@Valid @RequestBody WbBoqMarketMaterialSaveReqVO createReqVO) {
        return success(wbBoqMarketMaterialService.createMarketMaterial(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新市场主材设备")
    @PreAuthorize("@ss.hasPermission('core:wb-boq-division:update')")
    public CommonResult<Boolean> updateMarketMaterial(@Valid @RequestBody WbBoqMarketMaterialSaveReqVO updateReqVO) {
        wbBoqMarketMaterialService.updateMarketMaterial(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除市场主材设备")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('core:wb-boq-division:delete')")
    public CommonResult<Boolean> deleteMarketMaterial(@RequestParam("id") Long id) {
        wbBoqMarketMaterialService.deleteMarketMaterial(id);
        return success(true);
    }

    @GetMapping("/list")
    @Operation(summary = "获得市场主材设备列表")
    @Parameter(name = "divisionId", description = "分部分项ID", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('core:wb-boq-division:query')")
    public CommonResult<List<WbBoqMarketMaterialRespVO>> getMarketMaterialList(@RequestParam("divisionId") Long divisionId) {
        return success(wbBoqMarketMaterialService.getMarketMaterialList(divisionId));
    }
}
