package co.yixiang.yshop.module.cart.controller.admin.storecart;

import co.yixiang.yshop.framework.common.pojo.CommonResult;
import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.module.cart.controller.admin.storecart.vo.StoreCartPageReqVO;
import co.yixiang.yshop.module.cart.controller.admin.storecart.vo.StoreCartRespVO;
import co.yixiang.yshop.module.cart.service.storecart.StoreCartService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 购物车")
@RestController
@RequestMapping("/cart/store-cart")
@Validated
public class StoreCartController {

    @Resource
    private StoreCartService storeCartService;


    @DeleteMapping("/delete")
    @Operation(summary = "删除购物车")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('cart:store-cart:delete')")
    public CommonResult<Boolean> deleteStoreCart(@RequestParam("id") Long id) {
        storeCartService.deleteStoreCart(id);
        return success(true);
    }



    @GetMapping("/page")
    @Operation(summary = "获得购物车分页")
    @PreAuthorize("@ss.hasPermission('cart:store-cart:query')")
    public CommonResult<PageResult<StoreCartRespVO>> getStoreCartPage(@Valid StoreCartPageReqVO pageVO) {
        return success(storeCartService.getStoreCartPage(pageVO));
    }



}
