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

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("multishopComboController")
@RequestMapping("/m/combo")
@Tag(name = "商品套餐")
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) {
        return ServerResponseEntity.success(comboService.getByComboId(comboId, AuthUserContext.get().getSysType()));
    }

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

    @PutMapping
    @Operation(summary = "更新商品套餐", description = "更新商品套餐")
    public ServerResponseEntity<Void> update(@Valid @RequestBody ComboDTO comboDTO) {
        comboService.update(comboDTO);
        return ServerResponseEntity.success();
    }

    @PutMapping("/updateComboStatus")
    @Operation(summary = "修改商品套餐状态", description = "修改商品套餐状态")
    public ServerResponseEntity<Void> updateComboStatus(@RequestBody ComboDTO comboDTO) {
        comboService.updateComboStatus(comboDTO.getComboId(), comboDTO.getStatus());
        return ServerResponseEntity.success();
    }
}
