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

import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.common.product.vo.GiveawaySpuVO;
import com.tmerclub.cloud.common.product.vo.SpuVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.security.AuthUserContext;
import com.tmerclub.cloud.product.dto.GiveawaySpuDTO;
import com.tmerclub.cloud.product.service.GiveawaySpuService;
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.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 赠品套装商品项
 *
 * @author tmerclub
 * @date 2022-08-16 11:11:59
 */
@RestController("multishopGiveawaySpuController")
@RequestMapping("/m/giveaway_spu")
@Tag(name = "赠品套装商品项")
public class GiveawaySpuController {

    @Autowired
    private GiveawaySpuService giveawaySpuService;

    @GetMapping("/page")
    @Operation(summary = "获取赠品套装商品项列表", description = "分页获取赠品套装商品项列表")
    public ServerResponseEntity<PageVO<GiveawaySpuVO>> page(@Valid PageDTO pageDTO) {
        PageVO<GiveawaySpuVO> giveawaySpuPage = giveawaySpuService.page(pageDTO);
        return ServerResponseEntity.success(giveawaySpuPage);
    }

    @GetMapping("/main_spu_page")
    @Operation(summary = "分页获取主赠送商品", description = "分页获取赠品信息")
    public ServerResponseEntity<PageVO<SpuVO>> getByGiveawaySpuId(@Valid PageDTO pageDTO, GiveawaySpuDTO giveawaySpuDTO) {
        Long shopId = AuthUserContext.get().getTenantId();
        giveawaySpuDTO.setShopId(shopId);
        giveawaySpuDTO.setSpuName(giveawaySpuDTO.getName());
        PageVO<SpuVO> mainSpuPage = giveawaySpuService.getMainSpuPage(pageDTO, giveawaySpuDTO);
        return ServerResponseEntity.success(mainSpuPage);
    }


}
