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

import com.neusoft.smart.pos.dto.member.request.MemberCardChangeRequest;
import com.neusoft.smart.pos.dto.member.request.UpdateCardPointRequest;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import com.neusoft.smart.pos.member.service.MemberBusinessService;
import com.neusoft.smart.pos.member.service.MemberCard4CanteenService;
import com.neusoft.smart.pos.member.service.MemberCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "会员卡管理restful接口", description = "会员卡管理restful接口")
@RestController
public class MemberCardController {
	
	@Autowired
	private MemberCardService memberCardService;
	
	@Autowired
	private MemberCard4CanteenService memberCard4CanteenService;
	
	@Autowired
	private MemberBusinessService memberBusinessService;
	
	@GetMapping("/memberCard/validate/{cardNum}")
	@ApiOperation(value = "会员卡号校验接口", notes = "会员卡号校验接口")
	public ResponseData<?> validateCardNum(@PathVariable String cardNum) {
		switch (memberBusinessService.getBusiness()) {
			case 1://普通会员卡
				memberCardService.validateByCardNum(cardNum);
				break;
			case 2://食堂会员卡
				memberCard4CanteenService.validateByCardNum(cardNum);
				break;
			default:
				memberCardService.validateByCardNum(cardNum);
		}
		return new ResponseData<>();
	}
	
	@PutMapping("/memberCard/change")
	@ApiOperation(value = "会员卡更换接口", notes = "会员卡更换接口")
	public ResponseData<String> changeCard(@RequestBody MemberCardChangeRequest memberCardChangeRequest) {
		switch (memberBusinessService.getBusiness()) {
			case 1://普通会员卡
				return new ResponseData<>(memberCardService.changeCard(memberCardChangeRequest));
			case 2://食堂会员卡
				return new ResponseData<>(memberCard4CanteenService.changeCard(memberCardChangeRequest));
			default:
				return new ResponseData<>(memberCardService.changeCard(memberCardChangeRequest));
		}
	}
	
	@PutMapping("/memberCard/card-point")
	public ResponseData<Integer> updateCardPoint(@RequestBody UpdateCardPointRequest request) {
		memberCardService.updateCardPoint(request);
		return new ResponseData<>(1);
	}
	
	@ApiOperation(value = "empty balance of member ")
	@PatchMapping("/memberCard/emptyBalance/{hidCode}")
	public ResponseData<?> emptyBalance(@PathVariable String hidCode) {
		memberCard4CanteenService.emptyBalance(hidCode);
		return new ResponseData<>();
	}
}
