package com.xiaoniu.system.groupgoods.groupbuying.controller;

import com.xiaoniu.common.core.resdata.Result;
import com.xiaoniu.common.core.resdata.RowsData;
import com.xiaoniu.common.core.vo.LabelAndValueVO;
import com.xiaoniu.system.groupgoods.groupbuying.dto.AddGroupBuyingDTO;
import com.xiaoniu.system.groupgoods.groupbuying.dto.EditGroupBuyingDTO;
import com.xiaoniu.system.groupgoods.groupbuying.dto.GroupBuyingListQueryDTO;
import com.xiaoniu.system.groupgoods.groupbuying.dto.SpecificationsListQueryDTO;
import com.xiaoniu.system.groupgoods.groupbuying.service.ITbGroupBuyingGoodsService;
import com.xiaoniu.system.groupgoods.groupbuying.vo.GroupBuyingDetailsVO;
import com.xiaoniu.system.groupgoods.groupbuying.vo.GroupBuyingListVO;
import com.xiaoniu.system.groupgoods.groupbuying.vo.SpecificationsListVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 团购商品表 前端控制器
 * </p>
 *
 * @author haoxuyang
 * @since 2024-10-18 09:19:39
 */
@Tag(name = "团购商品管理")
@RestController
@RequestMapping("/groupBuying")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TbGroupBuyingGoodsController {

    private final ITbGroupBuyingGoodsService groupBuyingGoodsService;

    @Operation(summary = "团购商品列表")
    @PostMapping("/list")
    public Result<RowsData<GroupBuyingListVO>> list(@RequestBody GroupBuyingListQueryDTO dto) {
        return Result.success("查询成功", groupBuyingGoodsService.groupBuyingList(dto));
    }

    @Operation(summary = "新增团购商品")
    @PostMapping("/add")
    public Result<String> add(@RequestBody @Validated AddGroupBuyingDTO dto) {
        groupBuyingGoodsService.addGroupBuying(dto);
        return Result.success("操作成功");
    }

    @Operation(summary = "修改团购商品")
    @PostMapping("/edit")
    public Result<String> edit(@RequestBody @Validated EditGroupBuyingDTO dto) {
        groupBuyingGoodsService.editGroupBuying(dto);
        return Result.success("操作成功");
    }

    @Operation(summary = "团购商品详情")
    @GetMapping("/details")
    public Result<GroupBuyingDetailsVO> details(@RequestParam Long id) {
        return Result.success("查询成功", groupBuyingGoodsService.details(id));
    }

    @Operation(summary = "根据类型获取商品信息")
    @GetMapping("/getGoodsListByType")
    public Result<List<LabelAndValueVO>> getGoodsListByType(@RequestParam Long goodType1Id, @RequestParam(required = false) Long goodType2Id) {
        return Result.success("查询成功", groupBuyingGoodsService.getGoodsListByType(goodType1Id,goodType2Id));
    }

    @Operation(summary = "根据团购id获取商品规格")
    @PostMapping("/getSpecificationsListByGroupId")
    public Result<List<SpecificationsListVO>> getSpecificationsListByGroupId(@RequestBody @Validated SpecificationsListQueryDTO dto) {
        return Result.success("查询成功", groupBuyingGoodsService.getSpecificationsListByGroupId(dto));
    }

    @Operation(summary = "根据商品id获取商品规格")
    @GetMapping("/getSpecificationsListByGoodsId")
    public Result<List<SpecificationsListVO>> getSpecificationsListByGoodsId(@RequestParam Long goodsId) {
        return Result.success("查询成功", groupBuyingGoodsService.getSpecificationsListByGoodsId(goodsId));
    }

    @Operation(summary = "删除团购商品")
    @GetMapping("/del")
    public Result<String> delGroupBuying(@RequestParam Long id) {
        groupBuyingGoodsService.delGroupBuying(id);
        return Result.success("操作成功");
    }

    @Operation(summary = "刷新团购商品")
    @GetMapping("/refreshGroupsGoods")
    public Result<String> refreshGroupsGoods() {
        groupBuyingGoodsService.refreshGroupsGoods();
        return Result.success("执行成功");
    }
}
