package cn.iocoder.yudao.module.member.controller.app.combo;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.member.controller.admin.combo.vo.ComboPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.combo.vo.ComboRespVO;
import cn.iocoder.yudao.module.member.dal.dataobject.combo.ComboDO;
import cn.iocoder.yudao.module.member.service.combo.ComboService;
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("/combo")
@Validated
public class AppComboController {

    @Resource
    private ComboService comboService;

    @GetMapping("/get")
    @Operation(summary = "获得套餐")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<ComboRespVO> getCombo(@RequestParam("id") Long id) {
        ComboDO combo = comboService.getCombo(id);
        return success(BeanUtils.toBean(combo, ComboRespVO.class));
    }
    @GetMapping("/page")
    @Operation(summary = "获得套餐分页")
    public CommonResult<PageResult<ComboRespVO>> getComboPage(@Valid ComboPageReqVO pageReqVO) {
        PageResult<ComboDO> pageResult = comboService.getComboPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ComboRespVO.class));
    }

}