package com.ym.mec.web.controller;

import com.ym.mec.biz.dal.dao.SysUserCashAccountDao;
import com.ym.mec.biz.dal.dao.TeacherDao;
import com.ym.mec.biz.dal.entity.SysUserCashAccount;
import com.ym.mec.biz.dal.entity.Teacher;
import com.ym.mec.biz.service.PracticeGroupService;
import com.ym.mec.biz.service.PracticeLessonApplyService;
import com.ym.mec.common.controller.BaseController;

import io.swagger.annotations.Api;

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;

@RequestMapping("api")
@Api(tags = "对外接口")
@RestController
public class APIController extends BaseController {

	@Autowired
	private SysUserCashAccountDao sysUserCashAccountDao;
	
	@Autowired
	private TeacherDao teacherDao;

	@Autowired
	private PracticeLessonApplyService practiceLessonApplyService;
	
	@Autowired
	private PracticeGroupService practiceGroupService;

	@GetMapping("/createCashAccount")
	public Boolean createCashAccount(Integer userId) {
		// 添加用户现金账户
		sysUserCashAccountDao.insert(new SysUserCashAccount(userId, "CNY"));

		return true;
	}

	@GetMapping("/queryTeacherOrganId")
	public Integer queryTeacherOrganId(Integer userId) {
		Teacher teacher = teacherDao.get(userId);
		if (teacher != null) {
			return teacher.getTeacherOrganId();
		}
		return null;
	}

	@GetMapping("/practiceSum")
	public Object practiceSum() {
		return succeed(practiceLessonApplyService.practiceSum());
	}
	@GetMapping("/isPurchasedPracticeCourse")
	public Boolean isPurchasedPracticeCourse(Integer userId) {
		return practiceGroupService.isPurchasedPracticeCourse(userId);
	}

}
