package com.cpop.mall.business.controller.mini;

import com.cpop.core.base.R;
import com.cpop.mall.business.bo.AdvanceOrderBo;
import com.cpop.mall.business.bo.ProductPageBo;
import com.cpop.mall.business.bo.ShoppingCartBo;
import com.cpop.mall.business.bo.ShoppingCartPageBo;
import com.cpop.mall.business.vo.MiniProductPageVo;
import com.cpop.mall.business.vo.MiniShoppingCartPageVo;
import com.mybatisflex.core.paginate.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.cpop.mall.business.entity.ShoppingCart;
import com.cpop.mall.business.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;

/**
 * 商城购物车表 控制层。
 *
 * @author DB
 * @since 2023-11-06
 */
@RestController
@Api(tags = "小程序-商城购物车接口")
@RequestMapping("/mini/shoppingCart")
public class MiniShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * @descriptions 分页查询小程序-商城-购物车分页
     * @author DB
     * @date 2023/11/06 14:10
     * @param bo 请求参数
     * @return: com.cpop.core.base.R<com.mybatisflex.core.paginate.Page<com.cpop.mall.business.vo.MiniShoppingCartPageVo>>
     */
    @GetMapping("/getMiniShoppingCartPage")
    @ApiOperation("分页查询小程序-商城-购物车分页")
    public R<Page<MiniShoppingCartPageVo>> getMiniShoppingCartPage(@ApiParam("分页参数") ShoppingCartPageBo bo) {
        Page<MiniShoppingCartPageVo> page = shoppingCartService.getMiniShoppingCartPage(bo);
        return R.ok(page);
    }

    /**
     * @descriptions 小程序-商城-购物车添加商品
     * @author DB
     * @date 2023/11/06 14:14
     * @param bo 请求参数
     * @return: com.cpop.core.base.R<java.lang.String>
     */
    @PostMapping("/insertShoppingCart")
    @ApiOperation("小程序-商城-购物车添加商品")
    public R<String> insertShoppingCart(@RequestBody @Validated @ApiParam("商城-购物车新增参数") ShoppingCartBo bo) {
        shoppingCartService.insertShoppingCart(bo);
        return R.ok();
    }

    /**
     * @descriptions 小程序-商城-购物车删除商
     * @author DB
     * @date 2023/11/06 14:14
     * @param ids 主键
     * @return: com.cpop.core.base.R<java.lang.String>
     */
    @DeleteMapping("/removeShoppingCart")
    @ApiOperation("小程序-商城-购物车删除商品")
    public R<Void> removeShoppingCart(@RequestParam("ids") @ApiParam("商城-购物车新增参数") String[] ids) {
        shoppingCartService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }
}
