package com.xiaoniu.system.pointsgoods.controller;

import com.xiaoniu.common.core.resdata.ChangeStatusDTO;
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.pointsgoods.dto.EditPointsGoodsDTO;
import com.xiaoniu.system.pointsgoods.dto.PointsGoodsQueryDTO;
import com.xiaoniu.system.pointsgoods.service.ITbPointsGoodsService;
import com.xiaoniu.system.pointsgoods.vo.AddPointsGoodsDTO;
import com.xiaoniu.system.pointsgoods.vo.PointsGoodsDetailsVO;
import com.xiaoniu.system.pointsgoods.vo.PointsGoodsListVO;
import com.xiaoniu.system.pointsgoods.vo.PointsGoodsSpecificationsVO;
import com.xiaoniu.system.store.goods.dto.SpecificationQueryDTO;
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-29 06:20:13
 */
@Tag(name = "积分商品管理")
@RestController
@RequestMapping("/pointsGoods")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TbPointsGoodsController {

    private final ITbPointsGoodsService tbPointsGoodsService;

    @Operation(summary = "积分商品列表")
    @PostMapping("/list")
    public Result<RowsData<PointsGoodsListVO>> list(@RequestBody PointsGoodsQueryDTO dto) {
        return Result.success("查询成功", tbPointsGoodsService.pointsGoodsList(dto));
    }

    @Operation(summary = "新增积分商品")
    @PostMapping("/add")
    public Result<String> add(@RequestBody @Validated AddPointsGoodsDTO dto) {
        tbPointsGoodsService.addPointsGoods(dto);
        return Result.success("操作成功");
    }

    @Operation(summary = "修改积分商品")
    @PostMapping("/edit")
    public Result<String> edit(@RequestBody @Validated EditPointsGoodsDTO dto) {
        tbPointsGoodsService.editPointsGoods(dto);
        return Result.success("操作成功");
    }

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

    @Operation(summary = "修改积分商品状态")
    @PostMapping("/changeStatus")
    public Result<String> changeStatus(@RequestBody ChangeStatusDTO dto) {
        tbPointsGoodsService.changeStatus(dto);
        return Result.success("操作成功");
    }

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

    @Operation(summary = "商品规格列表")
    @PostMapping("/specificationList")
    public Result<List<PointsGoodsSpecificationsVO>> specificationList(@RequestBody @Validated SpecificationQueryDTO dto) {
        return Result.success("查询成功", tbPointsGoodsService.specificationList(dto));
    }

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

    @Operation(summary = "刷新积分商品")
    @GetMapping("/refreshPointsGoods")
    public Result<String> refreshUserStatistics() {
        tbPointsGoodsService.refreshUserStatistics();
        return Result.success("执行成功");
    }
}
