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.progresspayment.ProgressPaymentModeCreateReqVO;
import com.yhy.module.core.controller.admin.workbench.vo.progresspayment.ProgressPaymentModeRespVO;
import com.yhy.module.core.controller.admin.workbench.vo.progresspayment.ProgressPaymentModeUpdateReqVO;
import com.yhy.module.core.service.workbench.ProgressPaymentModeService;
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/progress-payment-mode")
@Validated
public class ProgressPaymentModeController {

    @Resource
    private ProgressPaymentModeService progressPaymentModeService;

    @PostMapping("/create")
    @Operation(summary = "创建进度款模式")
    @PreAuthorize("@ss.hasPermission('core:wb-progress-payment:create')")
    public CommonResult<Long> createProgressPaymentMode(@Valid @RequestBody ProgressPaymentModeCreateReqVO createReqVO) {
        return success(progressPaymentModeService.createProgressPaymentMode(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新进度款模式")
    @PreAuthorize("@ss.hasPermission('core:wb-progress-payment:update')")
    public CommonResult<Boolean> updateProgressPaymentMode(@Valid @RequestBody ProgressPaymentModeUpdateReqVO updateReqVO) {
        progressPaymentModeService.updateProgressPaymentMode(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除进度款模式")
    @Parameter(name = "id", description = "进度款模式ID", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('core:wb-progress-payment:delete')")
    public CommonResult<Boolean> deleteProgressPaymentMode(@RequestParam("id") Long id) {
        progressPaymentModeService.deleteProgressPaymentMode(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获取进度款模式详情")
    @Parameter(name = "id", description = "进度款模式ID", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('core:wb-progress-payment:query')")
    public CommonResult<ProgressPaymentModeRespVO> getProgressPaymentMode(@RequestParam("id") Long id) {
        return success(progressPaymentModeService.getProgressPaymentMode(id));
    }

    @GetMapping("/list")
    @Operation(summary = "获取项目下的进度款模式列表")
    @Parameter(name = "projectId", description = "项目ID", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('core:wb-progress-payment:query')")
    public CommonResult<List<ProgressPaymentModeRespVO>> getProgressPaymentModeList(@RequestParam("projectId") Long projectId) {
        return success(progressPaymentModeService.getProgressPaymentModeList(projectId));
    }
}
