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


import com.neusoft.smart.pos.dto.trade.request.*;
import com.neusoft.smart.pos.dto.trade.response.*;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import com.neusoft.smart.pos.gateway.service.OrderService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(value = "订单管理使用rest接口", description = "订单管理使用rest接口")
@RestController
@RequestMapping(path = "/unionService/order")
@Validated
public class OrderController {

	@Autowired
	private OrderService orderService;

	@ApiOperation(value = "订单生成使用接口", notes = "订单生成使用方法")
	@PostMapping("/order")
	public ResponseData<PostOrderResponse> saveOrder(@RequestBody PostOrderRequest orderRequest){
		return new ResponseData<>(orderService.saveOrder(orderRequest));
	}

	@ApiOperation(value = "会员卡充值订单生成接口", notes = "会员卡充值订单生成方法")
	@PostMapping("/rechargeOrder")
	public ResponseData<PostRechargeOrderResponse> saveRechargeOrder(@Valid @RequestBody PostRechargeOrderRequest rechargeOrderRequest, BindingResult bindingResult) {
		return new ResponseData<>(orderService.saveRechargeOrder(rechargeOrderRequest));
	}

	@ApiOperation(value = "微信订单生成接口", notes = "微信订单生成方法")
	@PostMapping("/wxOrder")
	public ResponseData<PostWxOrderResponse> saveWxOrder(@RequestBody PostWxOrderRequest wxOrderRequest) {
		return new ResponseData<>(orderService.saveWxOrder(wxOrderRequest));
	}

	@ApiOperation(value = "订单及预付单生成统一接口", notes = "订单及预付单生成统一方法")
	@PostMapping("/unionPayOrder")
	public ResponseData<PostUnionPayOrderResponse> saveUnionPayOrder(@Valid @RequestBody PostUnionPayOrderRequest unionPayOrderRequest, BindingResult bindingResult){
		return new ResponseData<>(orderService.saveUnionPayOrder(unionPayOrderRequest));
	}

	@ApiOperation(value = "订单支付完成接口", notes = "根据订单编号更新订单支付状态方法")
	@PutMapping("/orderPaySuccess")
	public ResponseData<PutOrderPaySuccessResponse> updateOrderPaySuccessStatus(@Valid @RequestBody PutOrderPaySuccessRequest orderPaySuccessRequest, BindingResult bindingResult) {
		return new ResponseData<>(orderService.updateOrderPaySuccessStatus(orderPaySuccessRequest));
	}
	
	@ApiOperation(value = "更新会员卡接口", notes = "根据订单更新会员卡信息")
	@PutMapping("/updateMemberHandle")
	public void updateMemberHandle(@Valid @RequestBody GetOrderResponse orderResponse, BindingResult bindingResult) {
		orderService.updateMemberHandle(orderResponse);
	}

	@ApiOperation(value = "充值订单支付完成接口", notes = "根据订单编号更新订单支付状态方法")
	@PutMapping("/rechargeOrderPaySuccess")
	public ResponseData<PutOrderPaySuccessResponse> updateRechargeOrderPaySuccessStatus(@Valid @RequestBody PutOrderPaySuccessRequest orderPaySuccessRequest, BindingResult bindingResult) {
		return new ResponseData<>(orderService.updateRechargeOrderPaySuccessStatus(orderPaySuccessRequest));
	}

	@ApiOperation(value = "会员卡支付接口", notes = "会员卡支付方法")
	@PutMapping("/memberCardPay")
	public ResponseData<PutMemberCardPayResponse> memberCardPay(@Valid @RequestBody PutMemberCardPayRequest memberCardPayRequest, BindingResult bindingResult) {
		return new ResponseData<>(orderService.memberCardPay(memberCardPayRequest));
	}

	@ApiOperation(value = "第三方支付单撤销接口", notes = "根据商户号订单编号撤销预付单信息方法")
	@PutMapping("/reverseOrder")
	public ResponseData<PutUnionReverseOrderResponse> reverseOrder(@RequestBody PutReverseOrderRequest reverseOrderRequest){
		return new ResponseData<>(orderService.reverseOrder(reverseOrderRequest));
	}
	
	@ApiOperation(value = "查询聚合支付平台订单支付状态接口", notes = "根据订单编号查询第三方平台支付状态方法")
	@GetMapping("/queryOrderPayStatusByThirdPlatform")
	public ResponseData<GetOrderPayStatusResponse> queryOrderPayStatusByThirdPlatform(@Valid @ModelAttribute GetOrderPayStatusRequest orderPayStatusRequest, BindingResult bindingResult) {
		return orderService.queryOrderPayStatusByThirdPlatform(orderPayStatusRequest);
	}

	@ApiOperation(value = "POS机订单补录接口", notes = "POS机订单补录方法")
	@PostMapping("/recordOrder")
	public ResponseData<PostRecordOrderResponse> recordOrder(@RequestBody PostRecordOrderRequest recordOrderRequest) {
		return new ResponseData<>(orderService.saveRecordOrder(recordOrderRequest));
	}
}
	