package com.iamberry.app.api.controller;

import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import com.iamberry.app.config.Response;
import com.iamberry.app.config.ResponseHeader;
import com.iamberry.app.face.CodeService;
import com.iamberry.app.face.LogService;
import com.iamberry.app.face.MachineService;
import com.iamberry.app.face.MessageService;
import com.iamberry.app.face.MilkService;
import com.iamberry.app.face.UserService;
import com.iamberry.wechat.tools.ResponseJson;

public class BaseController {

	@Autowired
	protected UserService userService;
	@Autowired
	protected MachineService machineService;
	@Autowired
	protected MilkService milkService;
	@Autowired
	LogService logService;
	@Autowired
	MessageService messageService;
	@Autowired
	HttpServletRequest request;
	@Autowired
	CodeService codeService;

	protected static Response createResponse(ResponseHeader header, Object payload) {
		return new Response(header, payload);
	}

	protected static Response createResponse(ResponseHeader header) {
		return new Response(header);
	}

	/**
	 * 判断用户的手机号码是否和短信验证码匹配
	 * @param phone				手机号码
	 * @param verificationCode	短信验证码
	 * @return
	 */
	protected int checkVerifyCode(String phone, String verificationCode, int codeScenario) {
		ResponseJson json = codeService.validCode(phone, verificationCode, codeScenario);
		if (json.getReturnCode() == 200) {
			return 1;
		} else {
			return -1;
		}
	}
}
