package com.mca.user.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import com.mca.user.mapper.UserMapper;
import com.mca.user.vo.UserSearchVO;
import com.mca.user.vo.UserVO;

@Service("userService")
public class UserService {
	
	@Resource(name="userMapper")
	UserMapper userMapper;
	
	public int selectUserIdCheck(String checkId) {
		return userMapper.selectUserIdCheck(checkId);
	}

	public int insertUser(UserVO userVO) {
		// TODO Auto-generated method stub
		
		try {
			/* bcrypt 사용 고려 */
			//BCryptPasswordEncoder bcryptPasswordEncoder = new BCryptPasswordEncoder(10);
			//userVO.setPassword(bcryptPasswordEncoder.encode(userVO.getPassword()));
			
			userMapper.insertUser(userVO);
			return 0;
			
		}catch (Exception e) {
			return -1;
		}
		
	}

	public UserVO selectUserInfo(String userid) {
		// TODO Auto-generated method stub
		return userMapper.selectUserInfo(userid);
	}

	public List<?> selectUserList(UserSearchVO userSearchVO) {
		// TODO Auto-generated method stub
		return userMapper.selectUserList(userSearchVO);
	}

	public int selectUserCount(UserSearchVO userSearchVO) {
		// TODO Auto-generated method stub
		return userMapper.selectUserCount(userSearchVO);
	}

	public int selectUserStandByCount() {
		// TODO Auto-generated method stub
		return userMapper.selectUserStandByCount();
	}

	public void updateUserSign(String userid) {
		// TODO Auto-generated method stub
		userMapper.updateUserSign(userid);
	}

	public void updateUserDelete(String userid) {
		// TODO Auto-generated method stub
		userMapper.updateUserDelete(userid);
	}

	public void updateUser(UserVO userVO) {
		// TODO Auto-generated method stub
		if(userVO.getPassword() != null && !userVO.getPassword().equals("")) {
			/* bcrypt 사용 고려 */
			//BCryptPasswordEncoder bcryptPasswordEncoder = new BCryptPasswordEncoder(10);
			//userVO.setPassword(bcryptPasswordEncoder.encode(userVO.getPassword()));
		}
		
		userMapper.updateUser(userVO);
	}
//아이디 비밀번호 찾기
	public UserVO findId(UserVO userVO) {
		// TODO Auto-generated method stub
		return userMapper.findId(userVO);
	}
	public UserVO findPwd(UserVO userVO) {
		// TODO Auto-generated method stub
		return userMapper.findPwd(userVO);
	}
	public void updatePwd(UserVO userVO) {
		// TODO Auto-generated method stub
		userMapper.updatePwd(userVO);
	}


}
