package com.ruoyi.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.code.PublicCommon;
import com.ruoyi.common.page.PageResult;
import com.ruoyi.controller.req.*;
import com.ruoyi.controller.resp.GoodsDetailResp;
import com.ruoyi.controller.resp.GoodsPageResp;
import com.ruoyi.frequency.mallgoods.service.MallGoodsService;
import com.ruoyi.frequency.mallgoodstype.entity.MallGoodsType;
import com.ruoyi.frequency.mallgoodstype.service.MallGoodsTypeService;
import com.ruoyi.response.ResponseData;
import com.ruoyi.vo.RyController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;
@CrossOrigin
@RestController
@RequestMapping("/api/goods")
@Api(tags = "商城")
public class ApiGoodsController extends RyController {

    @Autowired
    private MallGoodsService goodsService;

    @Autowired
    private MallGoodsTypeService goodsTypeService;


    @RequestMapping(value = "/goodsTypeList", method = RequestMethod.POST)
    @ApiOperation(value = "商品类型列表")
    public ResponseData<List<MallGoodsType>> goodsTypeList() {
        List<MallGoodsType> list = goodsTypeService.list(new QueryWrapper<MallGoodsType>().lambda()
                .eq(MallGoodsType::getDelFlag, PublicCommon.启用).orderByAsc(MallGoodsType::getSort));
        return ResponseData.success(list);
    }

    @RequestMapping(value = "/goodsPage", method = RequestMethod.POST)
    @ApiOperation(value = "商品列表")
    public ResponseData<PageResult<GoodsPageResp>> goodsPage(@RequestBody GoodsPageReq req) {
        return goodsService.goodsPage(req,getUserVo());
    }

    @RequestMapping(value = "/goodsDetail", method = RequestMethod.POST)
    @ApiOperation(value = "商品列表_详情")
    public ResponseData<GoodsDetailResp> goodsDetail(@RequestBody @NotNull(message = "商品id不能为空") Long goodsId) {
        return goodsService.goodsDetail(goodsId,getUserVo());
    }
}
