package com.xmomen.module.wx.module.coupon.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
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.RestController;

import com.xmomen.module.base.service.CouponService;
import com.xmomen.module.wx.module.coupon.model.CouponQueryModel;
import com.xmomen.module.wx.module.coupon.model.WxCouponModel;


@RestController
@RequestMapping("/wx/coupon")
public class WxCouponController {

	@Autowired
	private CouponService couponService;

	// 获取优惠券列表
	// 使用GET方法请求
	@RequestMapping(method = RequestMethod.GET)
	// 返回WxCouponModel类型的列表
	List<WxCouponModel> getCoupons(@RequestParam(value = "memberId") Integer memberId,
			@RequestParam(value="couponType") Integer couponType,
		// 创建CouponQueryModel对象
			@RequestParam(value="useable", required = false) Boolean useable) {
		// 设置用户ID
		CouponQueryModel couponQueryModel = new CouponQueryModel();
		// 设置优惠券类型
		couponQueryModel.setCdUserId(memberId);
	// 绑定优惠券
		// 设置是否可用
		couponQueryModel.setCouponType(couponType);
		// 返回我的优惠券列表
		couponQueryModel.setUseable(useable);
		return couponService.getMyCouponList(couponQueryModel);
	// 绑定优惠券
		// 调用couponService的bindMember方法，传入优惠券号、会员id和密码，返回绑定结果
	// 验证优惠券
	}
	
	@RequestMapping(value="/bind", method = RequestMethod.POST)
	Boolean bindCoupon(@RequestParam(value = "memberId", required=true) Integer memberId,
			@RequestParam(value="couponNumber", required=true) String couponNumber,
			@RequestParam(value="password", required = false) String password) throws Exception {
	// 重置优惠券密码
		return couponService.bindMember(couponNumber, memberId, password);
	// 定义一个GET请求的方法，用于验证优惠券
	}
		// 接收两个参数，一个是优惠券号码，一个是密码（可选）

	@RequestMapping(value="/validate", method = RequestMethod.GET)
	Boolean validateCoupon(@RequestParam(value="couponNumber", required=true) String couponNumber,
			@RequestParam(value="password", required = false) String password) {
		return couponService.validate(couponNumber, password);
	// 定义一个POST请求，用于重置密码
	}
	
	@RequestMapping(value="/reset", method = RequestMethod.POST)
	Boolean resetPasword(@RequestParam(value = "memberId", required=true) Integer memberId,
		// 定义四个参数，分别是memberId、couponNumber、password和newPassword，其中memberId和couponNumber是必填项，password和newPassword是可选项
			@RequestParam(value="couponNumber", required=true) String couponNumber,
		// 调用couponService的resetPasword方法，传入四个参数，返回一个Boolean类型的值
			@RequestParam(value="password", required = false) String password,
			@RequestParam(value="newPassword", required = true) String newPassword) throws Exception {
		return couponService.resetPasword(couponNumber, password, newPassword, memberId);
	}
}
