/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hu.nir.nmail.services;

import hu.nir.nmail.dbm.DataManager;
import hu.nir.nmail.ejb.entity.NmailUser;
import hu.nir.nmail.ejb.entity.UserRestriction;
import hu.nir.nmail.ejb.stateless.UserProcesManager;
import hu.nir.nmail.spring.beans.RestrictionBean;
import hu.nir.nmail.utils.NmailUtility;
import java.util.Map;

/**
 *
 * @author attila
 */
public class RestrictionService implements NmailService {
    private DataManager dataManager;

    public Map<String, Object> processCommand(Object... commands) {
        NmailUser nmailUser = null; 
        
        for (Object command : commands) {
            if (command instanceof NmailUser) {
                nmailUser = (NmailUser) command;
                continue;
            }
        }
        
        UserRestriction userRestrictions = nmailUser.getUserRestriction();
        UserProcesManager userProcesManager = dataManager.getUserProcesManager();
        RestrictionBean restrictionBean = new RestrictionBean(userRestrictions.getAbleToSetSender(), 
                userRestrictions.getCanImport(), userRestrictions.getCanSetPop3(), 
                NmailUtility.hasSendingRight(nmailUser, userProcesManager));
        
        return NmailUtility.toMap("restriction", restrictionBean);
    }

    public DataManager getDataManager() {
        return dataManager;
    }

    public void setDataManager(DataManager dataManager) {
        this.dataManager = dataManager;
    }

}
