package org.jeecg.modules.xcx.goods.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.TokenUtils;
import org.jeecg.modules.xcx.goods.req.*;
import org.jeecg.modules.xcx.goods.service.IGoodsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(tags = "商品接口")
@Slf4j
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Resource
    private IGoodsService goodsService;


    /**
     * 商品列表
     * @param goodsListReq
     * @return
     */
    @ApiOperation(value = "分页", notes = "分页")
    @GetMapping("/page")
    public Result<?> getGoodsList(GoodsListReq goodsListReq){
        return goodsService.getGoodsList(goodsListReq);
    }

    /**
     * 商品详情
     * @return
     */
    @ApiOperation(value = "详情", notes = "详情")
    @GetMapping("/one")
    public Result<?> getGoodsOne(GoodsDetailReq goodsDetailReq){
        return goodsService.getGoodsOne(goodsDetailReq);
    }


    @ApiOperation(value = "加入购物车", notes = "加入购物车")
    @PostMapping("/join/shopping/cart")
    public Result<?> joinShoppingCart(HttpServletRequest request , JoinShoppingCartReq joinShoppingCartReq){
        joinShoppingCartReq.setToken(TokenUtils.getTokenByRequest(request));
        return goodsService.joinShoppingCart(joinShoppingCartReq);
    }

    @ApiOperation(value = "购物车分页", notes = "购物车分页")
    @GetMapping("/shopping/cart/page")
    public Result<?> shoppingCartPage(HttpServletRequest request , ShoppingCartPageReq shoppingCartPageReq){
        shoppingCartPageReq.setToken(TokenUtils.getTokenByRequest(request));
        return goodsService.shoppingCartPage(shoppingCartPageReq);
    }

    @ApiOperation(value = "删除购物车", notes = "删除购物车")
    @PostMapping("/shopping/cart/delete")
    public Result<?> deleteShoppingCart(HttpServletRequest request , DeleteShoppingCartReq deleteShoppingCartReq){
        deleteShoppingCartReq.setToken(TokenUtils.getTokenByRequest(request));
        return goodsService.deleteShoppingCart(deleteShoppingCartReq);
    }

    @ApiOperation(value = "购物车增加数量或减少数量")
    @PostMapping("/shopping/cart/add/or/delete")
    public Result<?> addOrDeleteNum(HttpServletRequest request , AddOrDeleteNumReq addOrDeleteNumReq){
        addOrDeleteNumReq.setToken(TokenUtils.getTokenByRequest(request));
        return goodsService.addOrDeleteNum(addOrDeleteNumReq);
    }

    @ApiOperation(value = "根据商品id获取规格")
    @GetMapping("/sku")
    public Result<?> getGoodsSku(String id){
        return goodsService.getGoodsSku(id);
    }


    @ApiOperation(value = "购物车修改多规格")
    @PostMapping("/shopping/cart/edit/sku")
    public Result<?> editShoppingCatByGoodsId(HttpServletRequest request , EditShoppingCatByGoodsIdReq editShoppingCatByGoodsIdReq){
        editShoppingCatByGoodsIdReq.setToken(TokenUtils.getTokenByRequest(request));
        return goodsService.editShoppingCatByGoodsId(editShoppingCatByGoodsIdReq);
    }

}
