package com.ruoyi.controller;

import com.ruoyi.annotations.UserLoginToken;
import com.ruoyi.controller.req.InsertShoppingCarReq;
import com.ruoyi.controller.req.ShoppingCarCreateOrderReq;
import com.ruoyi.controller.req.ShoppingCartSettlementReq;
import com.ruoyi.frequency.mallshoppingcar.service.MallShoppingCarService;
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.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/api/goods")
@Api(tags = "购物车")
public class ApiShoppingCarController extends RyController {


    @Autowired
    private MallShoppingCarService shoppingCarService;

    @UserLoginToken
    @RequestMapping(value = "/shoppingCarList", method = RequestMethod.POST)
    @ApiOperation(value = "购物车列表")
    public ResponseData shoppingCarList() {
        return shoppingCarService.shoppingCarList(getUserVo());
    }

    @UserLoginToken
    @RequestMapping(value = "/shoppingCarSettlement", method = RequestMethod.POST)
    @ApiOperation(value = "购物车订单结算")
    public ResponseData shoppingCarSettlement(@RequestBody ShoppingCartSettlementReq req) {
        return ResponseData.success(shoppingCarService.shoppingCarSettlement(req,getUserVo()));
    }

    @UserLoginToken
    @RequestMapping(value = "/insertShoppingCar", method = RequestMethod.POST)
    @ApiOperation(value = "加入购物车")
    public ResponseData insertShoppingCar(@RequestBody InsertShoppingCarReq req) {
        return shoppingCarService.insertShoppingCar(req,getUserVo());
    }


    @UserLoginToken
    @RequestMapping(value = "/removeShoppingCarGoods", method = RequestMethod.POST)
    @ApiOperation(value = "删除购物车商品")
    public ResponseData removeShoppingCarGoods(@Valid @NotEmpty(message = "参数不能为空") @RequestBody List<Long> ids) {
        return shoppingCarService.removeShoppingCarGoods(ids,getUserVo());
    }

    @UserLoginToken
    @RequestMapping(value = "/shoppingCarCreateOrder", method = RequestMethod.POST)
    @ApiOperation(value = "购物车创建订单")
    public ResponseData shoppingCarCreateOrder(@RequestBody ShoppingCarCreateOrderReq req) {
        return shoppingCarService.shoppingCarCreateOrder(req,getUserVo());
    }

}
