package cn.newfeifan.mall.module.trade.controller.app.ordersettlement;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import cn.newfeifan.mall.framework.common.pojo.PageResult;
import cn.newfeifan.mall.framework.common.pojo.CommonResult;
import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
import static cn.newfeifan.mall.framework.common.pojo.CommonResult.success;

import cn.newfeifan.mall.module.trade.controller.app.ordersettlement.vo.*;
import cn.newfeifan.mall.module.trade.dal.dataobject.ordersettlement.OrderSettlementDO;
import cn.newfeifan.mall.module.trade.service.ordersettlement.OrderSettlementService;

@Tag(name = "用户 APP - 订单结算表,记录有那些订单参与了本次结算")
@RestController
@RequestMapping("/trade/order-settlement")
@Validated
public class AppOrderSettlementController {

    @Resource
    private OrderSettlementService orderSettlementService;

    @PostMapping("/create")
    @Operation(summary = "创建订单结算表,记录有那些订单参与了本次结算")
    public CommonResult<Long> createOrderSettlement(@Valid @RequestBody AppOrderSettlementSaveReqVO createReqVO) {
        return success(orderSettlementService.createOrderSettlement(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新订单结算表,记录有那些订单参与了本次结算")
    public CommonResult<Boolean> updateOrderSettlement(@Valid @RequestBody AppOrderSettlementSaveReqVO updateReqVO) {
        orderSettlementService.updateOrderSettlement(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除订单结算表,记录有那些订单参与了本次结算")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteOrderSettlement(@RequestParam("id") Long id) {
        orderSettlementService.deleteOrderSettlement(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得订单结算表,记录有那些订单参与了本次结算")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppOrderSettlementRespVO> getOrderSettlement(@RequestParam("id") Long id) {
        OrderSettlementDO orderSettlement = orderSettlementService.getOrderSettlement(id);
        return success(BeanUtils.toBean(orderSettlement, AppOrderSettlementRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得订单结算表,记录有那些订单参与了本次结算分页")
    public CommonResult<PageResult<AppOrderSettlementRespVO>> getOrderSettlementPage(@Valid AppOrderSettlementPageReqVO pageReqVO) {
        PageResult<OrderSettlementDO> pageResult = orderSettlementService.getOrderSettlementPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AppOrderSettlementRespVO.class));
    }

}