package shop.alien.store.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.store.service.LifeStoreOrderService;

import java.util.List;
import java.util.Map;

@Api(tags = {"一期-门店订单"})
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/storeOrder")
@RequiredArgsConstructor
public class LifeStoreOrderController {

    private final LifeStoreOrderService lifeStoreOrderService;

    @ApiOperation("订单列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "页数", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "size", value = "页容", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "storeId", value = "门店id", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "status", value = "状态", dataType = "Integer", paramType = "query", required = true)})
    @GetMapping("/getOrderListByStatus")
    public R<Map<String, Object>> getOrderListByStatus(@RequestParam(value = "page", defaultValue = "1") int page,
                                                       @RequestParam(value = "size", defaultValue = "10") int size,
                                                       @RequestParam("storeId") String storeId,
                                                       @RequestParam("status") String status) {
        log.info("LifeStoreOrderController.getOrderListByStatus?page={},size={},storeId={},status={}", page, size, storeId, status);
        return R.data(lifeStoreOrderService.getOrderListByStatus(page, size, storeId, status));
    }

    @ApiOperation("订单详情")
    @ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户id", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "storeId", value = "门店id", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "status", value = "状态", dataType = "Integer", paramType = "query", required = true)})
    @GetMapping("/getOrderById")
    public R<List<Map<String, Object>>> getOrderById(@RequestParam("userId") String userId,
                                                     @RequestParam("status") int status,
                                                     @RequestParam("storeId") String storeId) {
        log.info("LifeStoreOrderController.getOrderById?userId={},status={},storeId={}", userId, status, storeId);
        return R.data(lifeStoreOrderService.getOrderById(userId, status, storeId));
    }
}
