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);
    }

}
