package cn.hmsoft.ltc.service.impl;

import java.sql.SQLException;
import org.springframework.stereotype.Component;
import cn.hmsoft.ltc.dao.UsersDao;
import cn.hmsoft.ltc.model.LoginRequest;
import cn.hmsoft.ltc.model.Users;
import cn.hmsoft.ltc.service.iface.UserService;
import javafx.collections.ObservableList;

/**
 * 用户登入、注册接口实现类
 * @author Administrator
 *
 */
@Component
public class UserServiceImpl implements UserService { 

	private UsersDao userDao = new UsersDao();
	
	@Override
	public void insertUser(Users user) {
		this.userDao.insertUser(user);
	}

	@Override
	public LoginRequest checkUserName(String userName, String passwd) throws SQLException {
		LoginRequest loginRequest = this.userDao.checkUserName(userName, passwd);
		return loginRequest;
	}

	@Override
	public boolean checkName(String userName) throws SQLException {
		return this.userDao.checkName(userName);
	}

	@Override
	public boolean updateUserPwd(String userName, String userPwd) {
		return this.userDao.updateUserPwd(userName, userPwd);
	}

	@Override
	public Integer selectUsersByUserName(String userName) throws SQLException {
		return this.userDao.selectUsersByUserName(userName);
	}

	public ObservableList<Users> listUsers() throws SQLException {
		return this.userDao.listUsers();
	}
	
	public boolean updateUserFirstLogin(Integer userId) {
		return this.userDao.updateUserFirstLogin(userId);
	}
	
	public Users selectUserByCourseCode(String courseCode) throws SQLException{
		return this.userDao.selectUserByCourseCode(courseCode);
	}
}
