/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 */

package com.yami.shop.groupbuy.platform.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.groupbuy.comment.dto.GroupProdAndSkuListDto;
import com.yami.shop.groupbuy.comment.dto.GroupProdDto;
import com.yami.shop.groupbuy.comment.model.GroupProd;
import com.yami.shop.groupbuy.comment.service.GroupProdService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 平台 --拼团商品
 */
@RestController
@RequiredArgsConstructor
    @RequestMapping("/platform/group/prod")
public class GroupProdController {
    private final GroupProdService groupProdService;

    /**
     * 分页查询
     *
     * @param page      分页对象
     * @param groupProd 拼团活动商品表
     * @return 分页数据
     */
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('group:prod:page')")
    public ResponseEntity<IPage<GroupProdDto>> getGroupProdPage(PageParam<GroupProd> page, GroupProd groupProd) {
        IPage<GroupProdDto> groupProdPage = groupProdService.getGroupProdPage(page, groupProd);
        return ResponseEntity.ok(groupProdPage);
    }
    /**
     * 通过id查询拼团活动商品表
     *
     * @param groupProdId id
     * @return 单个数据
     */
    @GetMapping("/getGroupProdAndSkuList/{groupProdId}")
    @PreAuthorize("@pms.hasPermission('group:prod:page')")
    public ResponseEntity<GroupProdAndSkuListDto> getGroupProdAndSkuListById(@PathVariable("groupProdId") Long groupProdId) {
        GroupProdAndSkuListDto groupProdAndSkuListDto = groupProdService.getGroupProdAndSkuListById(groupProdId);
        return ResponseEntity.ok(groupProdAndSkuListDto);
    }


}
