package com.neusoft.smart.pos.payorder.controller;

import com.neusoft.smart.pos.dto.order.request.*;
import com.neusoft.smart.pos.dto.order.response.*;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import com.neusoft.smart.pos.payorder.service.PayRefundOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(value = "退款订单管理接口", description = "退款订单管理接口")
@RestController
@RequestMapping(path = "/orderRefund")
@Validated
public class PayRefundOrderController {
    private PayRefundOrderService refundOrderService = new PayRefundOrderService();//ServiceFactory.getRefundOrderServiceInstance(null,null);

    @ApiOperation(value = "退款订单生成使用接口", notes = "退款订单生成使用方法")
    @PostMapping("/createRefundOrder")
    public ResponseData<PostRefundOrderResponse> createRefundOrder(@RequestBody PostCreateRefundOrderRequest createRefundOrderRequest) {
        return new ResponseData<>(refundOrderService.createRefundOrder(createRefundOrderRequest));
    }

    @ApiOperation(value = "退款订单保存使用接口", notes = "根据订单编号更新退款订单信息方法")
    @PostMapping("/saveRefundOrder")
    public ResponseData<PostRefundOrderResponse> saveRefundOrder(@RequestBody PostSaveRefundOrderRequest saveRefundOrderRequest) {
        return new ResponseData<>(refundOrderService.saveRefundOrder(saveRefundOrderRequest));
    }

    @ApiOperation(value = "退款订单取消使用接口", notes = "根据订单编号设置退款订单状态为已取消的方法")
    @PutMapping("/cancleRefundOrder")
    public ResponseData<PutCancelRefundOrderResponse> cancleRefundOrder(@RequestBody PutCancelRefundOrderRequest cancleRefundOrderRequest) {
        return new ResponseData<>(refundOrderService.cancleRefundOrder(cancleRefundOrderRequest));
    }

    @ApiOperation(value = "更新退款订单状态接口", notes = "根据订单编号计算并更新退款订单状态方法")
    @PutMapping("/updatRefundeOrderStatus")
    public ResponseData<PutUpdateRefundOrderStatusResponse> updateRefundOrderStatus(@Valid @RequestBody PutUpdateRefundOrderStatusRequest updateRefundOrderStatusRequest, BindingResult bindingResult) {
        return new ResponseData<>(refundOrderService.updateOrderStatus(updateRefundOrderStatusRequest));
    }
    //setOrderStatus
    @ApiOperation(value = "设置退款订单状态接口", notes = "根据订单编号设置退款订单状态方法")
    @PutMapping("/setRefundOrderStatus")
    public ResponseData<PutSetRefundOrderStatusResponse> setRefundOrderStatus(@Valid @RequestBody PutSetRefundOrderStatusRequest setRefundOrderStatusRequest, BindingResult bindingResult) {
        return new ResponseData<>(refundOrderService.setRefundOrderStatus(setRefundOrderStatusRequest));
    }

    @ApiOperation(value = "退款订单信息查询接口", notes = "根据订单编号查询退款订单信息方法")
    @GetMapping("/getRefundOrderInfo")
    public ResponseData<GetRefundOrderInfoResponse> getRefundOrderInfo(@RequestParam(value="orderNumber",defaultValue = "") String orderNumber) {
        return new ResponseData<>(refundOrderService.getRefundOrderInfoByOrderNumber(orderNumber));
    }

    @ApiOperation(value = "退款订单商品信息列表查询接口", notes = "退款订单商品信息列表查询方法")
    @GetMapping("/geRefundtOrderGoodsList")
    public ResponseData<GetRefundOrderInfoResponse> getRefundOrderGoodsList(@RequestParam(value="orderNumber",defaultValue = "") String orderNumber) {
        return new ResponseData<>(refundOrderService.getRefundOrderGoodsListByOrderNumber(orderNumber));
    }

    //doPay
    @ApiOperation(value = "退款订单支付使用接口", notes = "开启退款订单支付流程的方法")
    @PostMapping("/doRefund")
    public ResponseData<PostDoRefundOrderResponse> doRefund(@RequestBody PostDoPayOrderRequest doPayOrderRequest) {
        return new ResponseData<>(refundOrderService.doRefund(doPayOrderRequest));
    }
}
