package com.ifish.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ifish.dto.JsonResult;
import com.ifish.enums.ResultEnum;
import com.ifish.exception.IfishException;
import com.ifish.service.GoldService;
import com.ifish.validator.AddValueParam;
import com.ifish.validator.PageParam;

/**
 * 金币
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/gold")
@ResponseBody
public class GoldAction {
	
	@Autowired
	private GoldService goldService;
	
	/**
	 * 新增金币
	 * @param addValueParam
	 * @param result
	 * @return
	 */
	@RequestMapping(value="/goldValue.do",method=RequestMethod.POST)
	public Object addGoldValue(@Validated AddValueParam addValueParam,BindingResult result) {
		//参数校验
		if(result.hasErrors()){
			throw new IfishException(ResultEnum.error401);
		}
		return goldService.addGoldValue(addValueParam);
	}
	
	/**
	 * 分页金币获取记录
	 * @param pageParam
	 * @param result
	 * @return
	 */
	@RequestMapping(value="/goldGetRecord.do",method=RequestMethod.GET)
	public Object getGoldGetRecordByPage(@Validated PageParam pageParam,BindingResult result){
		//参数校验
		if(result.hasErrors()){
			throw new IfishException(ResultEnum.error401);
		}
		return goldService.getGoldGetRecordByPage(pageParam);
	}
	
	/**
	 * 分页金币消耗记录
	 * @param pageParam
	 * @param result
	 * @return
	 */
	@RequestMapping(value="/goldExpendRecord.do",method=RequestMethod.GET)
	public Object getGoldExpendRecordByPage(@Validated PageParam pageParam,BindingResult result){
		//参数校验
		if(result.hasErrors()){
			throw new IfishException(ResultEnum.error401);
		}
		return goldService.getGoldExpendRecordByPage(pageParam);
	}
	
	/**
	 * 签到
	 * @param userId
	 * @return
	 */
	@RequestMapping(value="/signin.do",method=RequestMethod.POST)
	public Object signin(@RequestParam Integer userId) {
		return goldService.signin(userId);
	}
	
	/**
	 * 砸金蛋
	 * @param userId
	 * @return
	 */
	@RequestMapping(value="/hitGoldenEgg.do",method=RequestMethod.POST)
	public Object hitGoldenEgg(@RequestParam Integer userId){
		return goldService.hitGoldenEgg(userId);
	}
	
	/**
	 * 爱鱼看看金币打赏
	 * @param userId 打赏人用户ID
	 * @param userId2 被打赏人用户ID
	 * @return
	 */
	@RequestMapping(value="/liveRoomReward/{userId}/{userId2}",method=RequestMethod.POST)
	public JsonResult<?> liveRoomReward(@PathVariable("userId")Integer userId,@PathVariable("userId2")Integer userId2){
		return goldService.liveRoomReward(userId, userId2);
	}
	
}
