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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import com.yhy.module.core.controller.admin.infoprice.vo.InfoPriceBookPageReqVO;
import com.yhy.module.core.controller.admin.infoprice.vo.InfoPriceBookRespVO;
import com.yhy.module.core.controller.admin.infoprice.vo.InfoPriceBookSaveReqVO;
import com.yhy.module.core.service.infoprice.InfoPriceBookService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

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

@Tag(name = "管理后台 - 信息价册")
@RestController
@RequestMapping("/core/info-price/book")
@Validated
public class InfoPriceBookController {

    @Resource
    private InfoPriceBookService infoPriceBookService;

    @PostMapping("/create")
    @Operation(summary = "创建信息价册")
    @PreAuthorize("@ss.hasPermission('core:info-price:create')")
    public CommonResult<Long> createInfoPriceBook(@Valid @RequestBody InfoPriceBookSaveReqVO createReqVO) {
        return success(infoPriceBookService.createInfoPriceBook(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新信息价册")
    @PreAuthorize("@ss.hasPermission('core:info-price:update')")
    public CommonResult<Boolean> updateInfoPriceBook(@Valid @RequestBody InfoPriceBookSaveReqVO updateReqVO) {
        infoPriceBookService.updateInfoPriceBook(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除信息价册")
    @Parameter(name = "id", description = "信息价册ID", required = true)
    @PreAuthorize("@ss.hasPermission('core:info-price:delete')")
    public CommonResult<Boolean> deleteInfoPriceBook(@RequestParam("id") Long id) {
        infoPriceBookService.deleteInfoPriceBook(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获取信息价册")
    @Parameter(name = "id", description = "信息价册ID", required = true)
    @PreAuthorize("@ss.hasPermission('core:info-price:query')")
    public CommonResult<InfoPriceBookRespVO> getInfoPriceBook(@RequestParam("id") Long id) {
        return success(infoPriceBookService.getInfoPriceBook(id));
    }

    @GetMapping("/page")
    @Operation(summary = "分页查询信息价册")
    @PreAuthorize("@ss.hasPermission('core:info-price:query')")
    public CommonResult<PageResult<InfoPriceBookRespVO>> getInfoPriceBookPage(@Valid InfoPriceBookPageReqVO pageReqVO) {
        return success(infoPriceBookService.getInfoPriceBookPage(pageReqVO));
    }
}
