package com.m2pool.lease.controller;


import com.m2pool.lease.annotation.LoginRequired;
import com.m2pool.lease.dto.PageResult;
import com.m2pool.lease.dto.Result;
import com.m2pool.lease.dto.ShopCartDto;
import com.m2pool.lease.service.LeaseShoppingCartService;
import com.m2pool.lease.vo.BaseVo;
import com.m2pool.lease.vo.PageVo;
import com.m2pool.lease.vo.ProductAndMachineVo;
import com.m2pool.lease.vo.ShoppingCartInfoURDVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 购物车表 前端控制器
 * </p>
 *
 * @author yyb
 * @since 2025-07-23
 */
@Api(tags = "购物车表控制器")
@LoginRequired
@RestController
@RequestMapping("/shopping/cart")
public class LeaseShoppingCartController {

    @Resource
    private LeaseShoppingCartService leaseShoppingCartService;

    @ApiOperation("添加商品到购物车(批量+单个)")
    @PostMapping("/addGoods")
    public Result<String> addGoods(@RequestBody List<ShoppingCartInfoURDVo> shoppingCartInfoURDVoList) {
        return leaseShoppingCartService.addGoods(shoppingCartInfoURDVoList);
    }


    @ApiOperation("查询购物车中商品列表")
    @PostMapping("/getGoodsList")
    public PageResult<ShopCartDto> getGoodsList(@RequestBody(required = false) PageVo pageVo) {
        if (pageVo == null){
            pageVo = new PageVo();
        }
        return leaseShoppingCartService.getGoodsList(pageVo);
    }

    @ApiOperation("批量删除购物车中商品")
    @PostMapping("/deleteBatchGoods")
    public Result<String> deleteBatchGoods(@RequestBody List<ProductAndMachineVo> baseVoList) {
        return leaseShoppingCartService.deleteBatchGoods(baseVoList);
    }

    @ApiOperation("删除购物车中商品")
    @PostMapping("/deleteGoods")
    @Deprecated
    public Result<String> deleteGoods(@RequestBody BaseVo baseVo) {
        return leaseShoppingCartService.deleteGoods(baseVo);
    }


    @ApiOperation("批量删除购物车中已下架商品")
    @PostMapping("/deleteBatchGoodsForIsDelete")
    public Result<String> deleteBatchGoodsForIsDelete() {
        return leaseShoppingCartService.deleteBatchGoodsForIsDelete();
    }



}

