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


import com.neusoft.smart.pos.dto.trade.request.PostSettlementRequest;
import com.neusoft.smart.pos.dto.trade.request.PutSettlementRequest;
import com.neusoft.smart.pos.dto.trade.response.GetSettlementResponse;
import com.neusoft.smart.pos.dto.trade.response.PostSettlementResponse;
import com.neusoft.smart.pos.dto.trade.response.PutSettlementResponse;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import com.neusoft.smart.pos.trade.service.TradeSettlementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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
@Validated
@RequestMapping(path = "/tradeSettlement")
public class TradeSettlementController {
	
	private final static Logger logger = LoggerFactory.getLogger(TradeSettlementController.class);
	
	@Autowired
	private TradeSettlementService tradeSettlementService;

	@ApiOperation(value = "商户结算信息添加使用接口", notes = "商户结算信息添加使用方法")
	@PostMapping("/settlement")
	public ResponseData<PostSettlementResponse> saveSettlement(@Valid @RequestBody PostSettlementRequest settlementRequest, BindingResult bindingResult) {
		return new ResponseData<>(tradeSettlementService.saveSettlement(settlementRequest));
	}

	@ApiOperation(value = "商户结算信息更新使用接口", notes = "商户结算信息更新使用方法")
	@PutMapping("/settlement")
	public ResponseData<PutSettlementResponse> updateSettlement(@Valid @RequestBody PutSettlementRequest settlementRequest, BindingResult bindingResult) {
		return new ResponseData<>(tradeSettlementService.updateSettlement(settlementRequest));
	}


	@ApiOperation(value = "商户结算信息查询使用接口", notes = "商户结算信息查询使用方法")
	@GetMapping("/settlement")
	public ResponseData<GetSettlementResponse> querySettlement(@RequestParam(value="serialNo",defaultValue = "") String serialNo) {
		return new ResponseData<>(tradeSettlementService.querySettlement(serialNo));
	}
	
	@ApiOperation(value = "商户结算信息查询使用接口", notes = "商户结算信息查询使用方法")
	@GetMapping("/settlement/{orgId}/{shopId}")
	public ResponseData<GetSettlementResponse> querySettlement(@PathVariable Integer orgId, @PathVariable Integer shopId) {
		return new ResponseData<>(tradeSettlementService.querySettlement(orgId, shopId));
	}
	
	@ApiOperation(value = "商户结算信息查询使用接口", notes = "商户结算信息查询使用方法")
	@GetMapping("/settlementByShopId")
	public ResponseData<GetSettlementResponse> querySettlementByShopId(@RequestParam(value="orgId",defaultValue = "0") Integer orgId, @RequestParam(value="shopId",defaultValue = "0") Integer shopId){
		return new ResponseData<>(tradeSettlementService.querySettlement(orgId, shopId));
	}
}

