package com.nisum.mytime.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nisum.mytime.exception.handler.MyTimeException;
import com.nisum.mytime.model.RoleMappingInfo;
import com.nisum.mytime.repository.RoleMappingInfoRepo;

@Service
public class RoleMappingServiceImpl implements RoleMappingService {

	@Autowired
	private RoleMappingInfoRepo roleMappingInfoRepo;

	@Override
	public void saveUniqueEmployeeAndRole(String employeeId, String roleId) throws MyTimeException {
		RoleMappingInfo roleMappingInfo;

		if (roleMappingInfoRepo.findByEmployeeIdAndRoleId(employeeId, roleId) == null) {
			roleMappingInfo = new RoleMappingInfo();
			roleMappingInfo.setEmployeeId(employeeId);
			roleMappingInfo.setRoleID(roleId);
			roleMappingInfo = updateEmployeeRoleInfo(roleMappingInfo);
		}
	}

	@Override
	public RoleMappingInfo updateEmployeeRoleInfo(RoleMappingInfo roleMappingInfo) throws MyTimeException {
		roleMappingInfoRepo.save(roleMappingInfo);
		return roleMappingInfo;
	}

	@Override
	public RoleMappingInfo getEmployeeAssignedRole() {

		return null;

	}

}
