package com.xingxi.api.controller;

import com.xingxi.api.common.BaseApiController;
import com.xingxi.api.model.CartsRequest;
import com.xingxi.api.model.CartsListResponse;
import com.xingxi.api.service.CartsServiceI;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 购物车相关
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/store/carts")
public class CartsApiController extends BaseApiController {

    private final CartsServiceI cartsService;

    /**
     * 购物车获取商品列表
     */
    @GetMapping("/list")
    public CartsListResponse list(CartsRequest request){
        return cartsService.list(getUserContext(), request);
    }

    /**
     * 购物车增加商品列表
     */
    @PostMapping("/add")
    public CartsListResponse add(@RequestBody @Valid CartsRequest request){
        return cartsService.add(getUserContext(),  request);
    }

    /**
     * 购物车选中/取消选中列表
     */
    @PostMapping("/checked")
    public CartsListResponse checked(@RequestBody @Valid CartsRequest request){
        return cartsService.checked(getUserContext(), request);
    }

    /**
     * 购物车选中所有列表
     */
    @PostMapping("/checkedAll")
    public CartsListResponse checkedAll(@RequestBody @Valid CartsRequest request){
        return cartsService.checkedAll(getUserContext(), request);
    }

    /**
     * 购物车取消选中所有列表
     */
    @PostMapping("/uncheckedAll")
    public CartsListResponse uncheckedAll(@RequestBody @Valid CartsRequest request){
        return cartsService.uncheckedAll(getUserContext(),  request);
    }

    /**
     * 购物车删除商品列表
     */
    @PostMapping("/delete")
    public CartsListResponse delete(@Valid @RequestBody CartsRequest request){
        return cartsService.delete(getUserContext(),  request);
    }

}
