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.CalcBaseRateCatalogRespVO;
import com.yhy.module.core.controller.admin.calcbaserate.vo.CalcBaseRateCatalogSaveReqVO;
import com.yhy.module.core.service.calcbaserate.CalcBaseRateCatalogService;
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/catalog")
@Validated
public class CalcBaseRateCatalogController {

    @Resource
    private CalcBaseRateCatalogService calcBaseRateCatalogService;

    @PostMapping("/create")
    @Operation(summary = "创建基数费率目录树节点")
    @PreAuthorize("@ss.hasPermission('core:calc-base-rate-catalog:create')")
    public CommonResult<Long> createCalcBaseRateCatalog(
            @Valid @Validated(CalcBaseRateCatalogSaveReqVO.CreateGroup.class)
            @RequestBody CalcBaseRateCatalogSaveReqVO createReqVO) {
        return success(calcBaseRateCatalogService.createCalcBaseRateCatalog(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新基数费率目录树节点")
    @PreAuthorize("@ss.hasPermission('core:calc-base-rate-catalog:update')")
    public CommonResult<Boolean> updateCalcBaseRateCatalog(
            @Valid @Validated(CalcBaseRateCatalogSaveReqVO.UpdateGroup.class)
            @RequestBody CalcBaseRateCatalogSaveReqVO updateReqVO) {
        calcBaseRateCatalogService.updateCalcBaseRateCatalog(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除基数费率目录树节点")
    @Parameter(name = "id", description = "节点ID", required = true)
    @PreAuthorize("@ss.hasPermission('core:calc-base-rate-catalog:delete')")
    public CommonResult<Boolean> deleteCalcBaseRateCatalog(@RequestParam("id") Long id) {
        calcBaseRateCatalogService.deleteCalcBaseRateCatalog(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获取基数费率目录树节点")
    @Parameter(name = "id", description = "节点ID", required = true)
    @PreAuthorize("@ss.hasPermission('core:calc-base-rate-catalog:query')")
    public CommonResult<CalcBaseRateCatalogRespVO> getCalcBaseRateCatalog(@RequestParam("id") Long id) {
        return success(calcBaseRateCatalogService.getCalcBaseRateCatalog(id));
    }

    @GetMapping("/tree")
    @Operation(summary = "获取基数费率目录树")
    @PreAuthorize("@ss.hasPermission('core:calc-base-rate-catalog:query')")
    public CommonResult<List<CalcBaseRateCatalogRespVO>> getCalcBaseRateCatalogTree() {
        return success(calcBaseRateCatalogService.getCalcBaseRateCatalogTree());
    }
}
