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

import com.neusoft.smart.pos.dto.member.request.MemberCapitalChangeQueryRequest;
import com.neusoft.smart.pos.dto.member.request.MemberPointWriteOffRequest;
import com.neusoft.smart.pos.dto.member.request.MemberRechargeRequest;
import com.neusoft.smart.pos.dto.member.request.MemberRefundRequest;
import com.neusoft.smart.pos.dto.member.request.MemberTransactionRequest;
import com.neusoft.smart.pos.dto.member.response.DetailedMemberResponse;
import com.neusoft.smart.pos.dto.member.response.MemberCapitalChangeResponse;
import com.neusoft.smart.pos.framework.bean.PaginationExtendBean;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import com.neusoft.smart.pos.framework.utils.SpringUtils;
import com.neusoft.smart.pos.member.service.MemberCapitalChangeService;
import com.neusoft.smart.pos.member.service.MemberCapitalChangeServiceInterface;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.math.BigDecimal;

@Api(value = "会员资金变动restful接口", description = "会员资金变动restful接口")
@RestController
public class MemberCapitalChangeController {
	
	@PostMapping("/memberCapitalChange/recharge")
	@ApiOperation(value = "会员卡充值接口", notes = "会员卡充值接口")
	public ResponseData<?> recharge(@Valid @RequestBody MemberRechargeRequest memberRechargeRequest, BindingResult bindingResult) {
		MemberCapitalChangeServiceInterface memberCapitalChangeService = SpringUtils.getBean(MemberCapitalChangeService.class);
		return new ResponseData<>(memberCapitalChangeService.recharge(memberRechargeRequest));
	}
	
	@PostMapping("/memberCapitalChange/trade")
	@ApiOperation(value = "会员卡消费接口", notes = "会员卡消费接口")
	public ResponseData<DetailedMemberResponse> trade(@Valid @RequestBody MemberTransactionRequest memberTransactionRequest, BindingResult bindingResult) {
		MemberCapitalChangeServiceInterface memberCapitalChangeService = SpringUtils.getBean(MemberCapitalChangeService.class);
		return new ResponseData<>(memberCapitalChangeService.trade(memberTransactionRequest));
	}
	
	@PostMapping("/memberCapitalChange/refund")
	@ApiOperation(value = "会员卡退款接口", notes = "会员卡退款接口")
	public ResponseData<?> refund(@Valid @RequestBody MemberRefundRequest memberRefundRequest, BindingResult bindingResult) {
		MemberCapitalChangeServiceInterface memberCapitalChangeService = SpringUtils.getBean(MemberCapitalChangeService.class);
		memberCapitalChangeService.refund(memberRefundRequest);
		return new ResponseData<>();
	}
	
	@PostMapping("/memberCapitalChange/point/writeOff")
	@ApiOperation(value = "会员卡积分核销接口", notes = "会员卡积分核销接口")
	public ResponseData<?> pointWriteOff(@Valid @RequestBody MemberPointWriteOffRequest memberPointWriteOffRequest, BindingResult bindingResult) {
		MemberCapitalChangeServiceInterface memberCapitalChangeService = SpringUtils.getBean(MemberCapitalChangeService.class);
		memberCapitalChangeService.pointWriteOff(memberPointWriteOffRequest);
		return new ResponseData<>();
	}
	
	@PostMapping("/memberCapitalChanges")
	@ApiOperation(value = "会员卡资金积分变得列表接口", notes = "会员卡资金积分变得列表接口")
	public ResponseData<?> list(@RequestBody MemberCapitalChangeQueryRequest memberCapitalChangeQueryRequest) {
		MemberCapitalChangeServiceInterface memberCapitalChangeService = SpringUtils.getBean(MemberCapitalChangeService.class);
		PaginationExtendBean<MemberCapitalChangeResponse> paginationExtendBean = new PaginationExtendBean<>();
		paginationExtendBean.setRows(memberCapitalChangeService.getList(memberCapitalChangeQueryRequest));
		paginationExtendBean.setTotal(memberCapitalChangeService.getCount(memberCapitalChangeQueryRequest));
		return new ResponseData<>(paginationExtendBean);
	}
	
	@PostMapping("/memberCapitalAmountPoint/{amount}")
	@ApiOperation(value = "会员卡资金积分变得列表接口", notes = "会员卡资金积分变得列表接口")
	public ResponseData<Integer> amount2Point(@PathVariable BigDecimal amount) {
		return new ResponseData<>(amount.intValue());
	}
}
