package com.ym.mec.student.controller;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;

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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.enums.KitGroupPurchaseTypeEnum;
import com.ym.mec.biz.service.ContractService;
import com.ym.mec.common.controller.BaseController;

@RequestMapping("contracts")
@Api(tags = "协议服务")
@RestController
public class ContractsController extends BaseController {

	@Autowired
	private SysUserFeignService sysUserFeignService;

	@Autowired
	private ContractService contractService;

	@ApiOperation("查询注册协议")
	@GetMapping(value = "queryRegisterContract")
	public Object queryRegisterContract() {
		SysUser sysUser = sysUserFeignService.queryUserInfo();
		if (sysUser == null) {
			return failed("获取用户信息失败");
		}
		return succeed(contractService.queryRegisterContract(sysUser.getId()));
	}

	@ApiOperation("查询商品协议")
	@GetMapping(value = "queryGoodsContract")
	public Object queryGoodsContract(String musicGroupId, String goodsIds, KitGroupPurchaseTypeEnum kitGroupPurchaseTypeEnum) {
		SysUser sysUser = sysUserFeignService.queryUserInfo();
		if (sysUser == null) {
			return failed("获取用户信息失败");
		}
		return succeed(contractService.queryGoodsContract(sysUser.getId(), musicGroupId, goodsIds, kitGroupPurchaseTypeEnum));
	}

	@ApiOperation("查询乐团课程协议")
	@GetMapping(value = "queryMusicGroupCoursesContract")
	public Object queryMusicGroupCoursesContract(String musicGroupId) {
		SysUser sysUser = sysUserFeignService.queryUserInfo();
		if (sysUser == null) {
			return failed("获取用户信息失败");
		}
		return succeed(contractService.queryMusicGroupCoursesContract(sysUser.getId(), musicGroupId));
	}

	@ApiOperation("查询VIP课程协议")
	@GetMapping(value = "queryVipGroupCoursesContract")
	public Object queryVipGroupCoursesContract(Long vipGroupId) {
		SysUser sysUser = sysUserFeignService.queryUserInfo();
		if (sysUser == null) {
			return failed("获取用户信息失败");
		}
		return succeed(contractService.queryVipGroupCoursesContract(sysUser.getId(), vipGroupId));
	}

	@ApiOperation("查询陪练课课程协议")
	@GetMapping(value = "queryPracticeCoursesContract")
	public Object queryPracticeCoursesContract(int courseSectionNum, Date startDate, Date endDate, BigDecimal fee) {
		SysUser sysUser = sysUserFeignService.queryUserInfo();
		if (sysUser == null) {
			return failed("获取用户信息失败");
		}
		return succeed(contractService.queryPracticeCoursesContract(sysUser.getId(), courseSectionNum, startDate, endDate, fee));
	}

	@ApiOperation("查询产品协议")
	@GetMapping(value = "queryProduceContract")
	public Object queryProduceContract(Integer userId, String musicGroupId) {
		if(Objects.isNull(userId)){
			SysUser sysUser = sysUserFeignService.queryUserInfo();
			if (sysUser == null) {
				return failed("获取用户信息失败");
			}
			userId = sysUser.getId();
		}
		return succeed(contractService.queryProductContract(userId,musicGroupId));
	}
}
