
package com.tmerclub.cloud.combo.controller.app;

import com.tmerclub.cloud.combo.service.ComboService;
import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.common.product.dto.ComboDTO;
import com.tmerclub.cloud.common.product.vo.ComboVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.security.AuthUserContext;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 套餐
 *
 * @author tmerclub
 * @date 2022-08-16 09:18:06
 */
@RestController("appComboController")
@RequestMapping("/ma/combo")
@Tag(name = "app-商品套餐")
public class ComboController {

    @Autowired
    private ComboService comboService;


    @GetMapping("/page")
    @Operation(summary = "获取套餐列表", description = "分页获取套餐列表")
    public ServerResponseEntity<PageVO<ComboVO>> page(@Valid PageDTO pageDTO, ComboDTO comboDTO) {
        PageVO<ComboVO> comboPage = comboService.page(pageDTO, comboDTO);
        return ServerResponseEntity.success(comboPage);
    }

    @GetMapping
    @Operation(summary = "获取套餐", description = "根据comboId获取套餐")
    public ServerResponseEntity<ComboVO> getByComboId(@RequestParam Long comboId) {
        // 用户端系统
        Integer sysType = 0;
        return ServerResponseEntity.success(comboService.getByComboId(comboId, sysType));
    }

    @PostMapping
    @Operation(summary = "保存套餐", description = "保存套餐")
    public ServerResponseEntity<Void> save(@Valid @RequestBody ComboDTO comboDTO) {
        comboService.save(comboDTO);
        return ServerResponseEntity.success();
    }

    @PostMapping("/pcGetCombo")
    @Operation(summary = "pc端获取套餐信息", description = "pc端获取套餐信息")
    public ServerResponseEntity<ComboVO> pcGetCombo(@RequestBody ComboDTO comboDTO) {
        return ServerResponseEntity.success(comboService.pcGetCombo(comboDTO, AuthUserContext.get().getSysType()));
    }
}
