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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import com.yhy.module.core.controller.admin.calcbaserate.vo.CalcBaseRateItemRespVO;
import com.yhy.module.core.controller.admin.calcbaserate.vo.CalcBaseRateItemSaveReqVO;
import com.yhy.module.core.service.calcbaserate.CalcBaseRateItemService;
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;

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

/**
 * 基数费率项 Controller
 *
 * @author yhy
 */
@Tag(name = "管理后台 - 基数费率项")
@RestController
@RequestMapping("/core/calc-base-rate/item")
@Validated
public class CalcBaseRateItemController {

    @Resource
    private CalcBaseRateItemService calcBaseRateItemService;

    @PostMapping("/create")
    @Operation(summary = "创建基数费率项")
    @PreAuthorize("@ss.hasPermission('core:calc-base-rate-item:create')")
    public CommonResult<Long> createCalcBaseRateItem(
            @Valid @Validated(CalcBaseRateItemSaveReqVO.CreateGroup.class)
            @RequestBody CalcBaseRateItemSaveReqVO createReqVO) {
        return success(calcBaseRateItemService.createCalcBaseRateItem(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新基数费率项")
    @PreAuthorize("@ss.hasPermission('core:calc-base-rate-item:update')")
    public CommonResult<Boolean> updateCalcBaseRateItem(
            @Valid @Validated(CalcBaseRateItemSaveReqVO.UpdateGroup.class)
            @RequestBody CalcBaseRateItemSaveReqVO updateReqVO) {
        calcBaseRateItemService.updateCalcBaseRateItem(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除基数费率项")
    @Parameter(name = "id", description = "费率项ID", required = true)
    @PreAuthorize("@ss.hasPermission('core:calc-base-rate-item:delete')")
    public CommonResult<Boolean> deleteCalcBaseRateItem(@RequestParam("id") Long id) {
        calcBaseRateItemService.deleteCalcBaseRateItem(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获取基数费率项")
    @Parameter(name = "id", description = "费率项ID", required = true)
    @PreAuthorize("@ss.hasPermission('core:calc-base-rate-item:query')")
    public CommonResult<CalcBaseRateItemRespVO> getCalcBaseRateItem(@RequestParam("id") Long id) {
        return success(calcBaseRateItemService.getCalcBaseRateItem(id));
    }

    @GetMapping("/list")
    @Operation(summary = "获取费率项列表")
    @Parameter(name = "calcBaseRateDirectoryId", description = "目录ID", required = true)
    @PreAuthorize("@ss.hasPermission('core:calc-base-rate-item:query')")
    public CommonResult<List<CalcBaseRateItemRespVO>> getCalcBaseRateItemList(
            @RequestParam("calcBaseRateDirectoryId") Long calcBaseRateDirectoryId) {
        return success(calcBaseRateItemService.getCalcBaseRateItemList(calcBaseRateDirectoryId));
    }
}
