package cn.ysk.cashier.controller.order;

import cn.ysk.cashier.dto.order.ReturnGroupOrderDto;
import cn.ysk.cashier.dto.order.TbGroupOrderInfoDto;
import cn.ysk.cashier.dto.order.TbGroupOrderInfoQueryCriteria;
import cn.ysk.cashier.service.order.TbGroupOrderInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
@RequiredArgsConstructor
@Api(tags = "团购卷订单管理")
@RequestMapping("/api/tbGroupOrderInfo")
public class TbGroupOrderInfoController {

    private final TbGroupOrderInfoService tbGroupOrderInfoService;

    @PostMapping
    @ApiOperation("团购卷订单列表")
    public ResponseEntity<Object> queryTbGroupOrderInfo(@RequestBody TbGroupOrderInfoQueryCriteria criteria){
        Pageable pageable = PageRequest.of(criteria.getPage(), criteria.getSize(),Sort.by(criteria.getSort()));
        return new ResponseEntity<>(tbGroupOrderInfoService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @GetMapping("/{id}")
    @ApiOperation("通过Id查询订单详情")
    public TbGroupOrderInfoDto queryTbGroupOrderInfo(@PathVariable("id") Integer id){
        return tbGroupOrderInfoService.findById(id);
    }

    @RequestMapping("returnGpOrder")
    public ResponseEntity<Object> returnOrder(@RequestBody ReturnGroupOrderDto param){
        return tbGroupOrderInfoService.returnOrder(param);
    }

}