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

import com.tmerclub.cloud.combo.dto.ComboSpuSkuDTO;
import com.tmerclub.cloud.combo.model.ComboSpuSku;
import com.tmerclub.cloud.combo.service.ComboSpuSkuService;
import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.common.product.vo.ComboSpuSkuVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.util.BeanUtil;
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.*;

import java.util.List;

/**
 * 套餐商品sku项
 *
 * @author tmerclub
 * @date 2022-08-16 09:18:06
 */
@RestController("appComboProdSkuController")
@RequestMapping("/comboProdSku")
@Tag(name = "app-套餐商品sku项")
public class ComboSpuSkuController {

    @Autowired
    private ComboSpuSkuService comboSpuSkuService;


    @GetMapping("/page")
    @Operation(summary = "获取套餐商品sku项列表", description = "分页获取套餐商品sku项列表")
    public ServerResponseEntity<PageVO<ComboSpuSkuVO>> page(@Valid PageDTO pageDTO) {
        PageVO<ComboSpuSkuVO> comboProdSkuPage = comboSpuSkuService.page(pageDTO);
        return ServerResponseEntity.success(comboProdSkuPage);
    }

    @PutMapping
    @Operation(summary = "更新套餐商品sku项", description = "更新套餐商品sku项")
    public ServerResponseEntity<Void> update(@Valid @RequestBody ComboSpuSkuDTO comboProdSkuDTO) {
        ComboSpuSku comboProdSku = BeanUtil.map(comboProdSkuDTO, ComboSpuSku.class);
        comboSpuSkuService.update(comboProdSku);
        return ServerResponseEntity.success();
    }

    @PostMapping("/comboSpuSkuList")
    @Operation(summary = "根据套餐id和商品id获取套餐商品sku信息", description = "根据套餐id和商品id获取套餐商品sku信息")
    public ServerResponseEntity<List<ComboSpuSkuVO>> comboSpuSkuList(@RequestBody ComboSpuSkuDTO comboSpuSkuDTO) {
        return ServerResponseEntity.success(comboSpuSkuService.comboSpuSkuListByComboIdAndSpuId(comboSpuSkuDTO));
    }
}
