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


import com.neusoft.smart.pos.dto.trade.request.PostGrantOrderRequest;
import com.neusoft.smart.pos.dto.trade.request.PostGrantToPayRequest;
import com.neusoft.smart.pos.dto.trade.request.PostReverseGrantRequest;
import com.neusoft.smart.pos.dto.trade.request.PostUnFreezeGrantRequest;
import com.neusoft.smart.pos.dto.trade.response.*;
import com.neusoft.smart.pos.framework.bean.PaginationExtendBean;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import com.neusoft.smart.pos.gateway.service.GrantOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(value = "资金预授权订单管理使用rest接口", description = "资金预授权订单管理使用rest接口")
@RestController
@RequestMapping(path = "/unionService/grantOrder")
@Validated
public class GrantOrderController {
	
	@Autowired
	private GrantOrderService grantOrderService;

	@ApiOperation(value = "资金授权订单生成使用接口", notes = "资金授权订单生成使用方法")
	@PostMapping("/grantOrder")
	public ResponseData<PostGrantOrderResponse> saveGrantOrder(@RequestBody PostGrantOrderRequest grantOrderRequest) {
		return new ResponseData<>(grantOrderService.saveGrantOrder(grantOrderRequest));
	}
	
	@ApiOperation(value = "资金授权资金解冻使用接口", notes = "资金授权资金解冻使用方法")
	@PostMapping("/unFreezeGrant")
	public ResponseData<PostUnFreezeGrantResponse> unFreezeGrant(@RequestBody PostUnFreezeGrantRequest unFreezeGrantRequest) {
		return new ResponseData<>(grantOrderService.unFreezeGrant(unFreezeGrantRequest));
	}
	
	@ApiOperation(value = "资金预授权撤销接口", notes = "资金预授权方法")
	@PostMapping("/reverseGrant")
	public ResponseData<PostReverseGrantResponse> reverseGrant(@RequestBody PostReverseGrantRequest reverseGrantRequest){
		return new ResponseData<>(grantOrderService.reverseGrant(reverseGrantRequest));
	}
	
	@ApiOperation(value = "资金授权订单列表查询使用接口", notes = "资金授权订单列表查询使用方法")
	@GetMapping("/grantOrders")
	ResponseData<PaginationExtendBean<GetGrantOrderResponse>> queryGrantOrders(@RequestParam(value="serialNo",defaultValue = "") String serialNo
			, @RequestParam(value="grantOrderNumber",defaultValue = "") String grantOrderNumber
			, @RequestParam(value="grantStatus",defaultValue = "") String grantStatus
			, @RequestParam(value="startTime",defaultValue = "") String startTime
			, @RequestParam(value="endTime",defaultValue = "") String endTime
			, @RequestParam(value = "offset", defaultValue = "0") Integer offset
			, @RequestParam(value = "limit", defaultValue = "10") Integer limit
			, @RequestParam(value = "isPage", defaultValue = "true") Boolean isPage){
		return new ResponseData<>(grantOrderService.queryGrantOrders(serialNo,grantOrderNumber,grantStatus,startTime,endTime,offset,limit,isPage));
	}
	
	@ApiOperation(value = "资金授权订单详情查询使用接口", notes = "资金授权订单详情查询使用方法")
	@GetMapping("/grantOrderDetails")
	ResponseData<GetGrantOrderDetailResponse> queryGrantOrderDetails(
			  @RequestParam(value="serialNo",defaultValue = "") String serialNo
			, @RequestParam(value="grantOrderNumber",defaultValue = "") String grantOrderNumber){
		return new ResponseData<>(grantOrderService.queryGrantOrderDetails(serialNo,grantOrderNumber));
	}
	
	@ApiOperation(value = "资金授权转支付接口", notes = "资金预授权转支付方法")
	@PostMapping("/grantToPay")
	public ResponseData<PostGrantToPayResponse> grantToPay(@RequestBody PostGrantToPayRequest grantToPayRequest) {
		return new ResponseData<>(grantOrderService.grantToPay(grantToPayRequest));
	}
	
}
	