package com.uas.platform.b2b.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.uas.platform.b2b.service.UserService;
import com.uas.platform.b2b.support.SystemSession;

/**
 * 企业请求
 * @author suntg
 * @date 2015年3月10日17:37:37
 */
@Controller
@RequestMapping(value = "/user")
public class UserController {

	@Autowired
	private UserService userService;
	
	/**
	 * 手机号是否可用
	 * @param tel
	 * @return
	 */
	@RequestMapping(value = "/telEnable", method = RequestMethod.GET)
	public ResponseEntity<Boolean> telEnable(String tel) {
		HttpHeaders headers = new HttpHeaders();
		headers.add("Content-Type", "application/text; charset=utf-8");
		return new ResponseEntity<Boolean>(userService.isTelUseable(tel), 
				headers, HttpStatus.OK);
	}
	
	/**
	 * 邮箱地址是否可用
	 * @param email
	 * @return
	 */
	@RequestMapping(value = "/emailEnable", method = RequestMethod.GET)
	public ResponseEntity<Boolean> emailEnable(String email) {
		HttpHeaders headers = new HttpHeaders();
		headers.add("Content-Type", "application/text; charset=utf-8");
		return new ResponseEntity<Boolean>(userService.isEmailUseable(email), 
				headers, HttpStatus.OK);
	}
	
	/**
	 * 邮箱地址是否可用
	 * @param email
	 * @return
	 */
	@RequestMapping(value = "/getuu", method = RequestMethod.POST)
	public ResponseEntity<ModelMap> getCurentUser() {
		HttpHeaders headers = new HttpHeaders();
		headers.add("Content-Type", "application/json; charset=utf-8");
		ModelMap map = new ModelMap();
		map.put("uu", SystemSession.getUser().getUserUU());
		map.put("username", SystemSession.getUser().getUserName());
		return new ResponseEntity<ModelMap>(map, headers, HttpStatus.OK);
	}
	
}
