package gov.va.med.esr.ui.admin.action;

import gov.va.med.esr.common.model.security.EEServiceRequestLite;
import gov.va.med.esr.common.model.security.EEServiceUserRequest;
import gov.va.med.fw.ui.struts.AbstractForm;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class ServiceUserForm extends AbstractForm{


	private static final long serialVersionUID = -5228491987784580237L;
	private String userId;
	private String userName ;
	private String password;
	private String contactName;
	private String contactPhone;
	private boolean active;
	private String changePassword;
	private String[] selectedRequests = null;
	
	private List requestList;
	private Map selectedRequestMap;
	
	public boolean isActive() {
		return active;
	}
	public void setActive(boolean active) {
		this.active = active;
	}
	public String getContactName() {
		return contactName;
	}
	public void setContactName(String contactName) {
		this.contactName = contactName;
	}
	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getContactPhone() {
		return contactPhone;
	}
	public void setContactPhone(String phone) {
		this.contactPhone = phone;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getChangePassword() {
		return changePassword;
	}
	public void setChangePassword(String changePassword) {
		this.changePassword = changePassword;
	}
	public List getRequestList() {
		return requestList;
	}
	public void setRequestList(List requestList) {
		this.requestList = new ArrayList();
		for  (int i=0; requestList != null && i<requestList.size();i++) {
			
			EEServiceRequestLite reqlite = (EEServiceRequestLite)requestList.get(i);
			ServiceRequestForm serviceRequestForm = new ServiceRequestForm();
			serviceRequestForm.setRequestId(reqlite.getEntityKey().getKeyValueAsString());
			serviceRequestForm.setName(reqlite.getName());
			serviceRequestForm.setDescription(reqlite.getDescription());
			this.requestList.add(serviceRequestForm);
		}
	}
	public void clearForm(){
		this.userId=null;
		this.userName=null;
		this.password=null;
		this.contactName=null;
		this.contactPhone=null;
		this.active=false;
		this.requestList=null;
		this.changePassword=null;
		this.selectedRequestMap=null;
		this.selectedRequests=null;
	}
	public Map getSelectedRequestMap() {
		return selectedRequestMap;
	}
	public void setSelectedRequestMap(Map selectedRequestMap) {
		this.selectedRequestMap = selectedRequestMap;
	}
	public void setSelectedRequestMap( Set  requests) {

		if ( requests == null || requests.size() <= 0 ){
			return;
		}
		
		selectedRequestMap = new HashMap();
		
		Iterator reqitr = requests.iterator();
		while(reqitr.hasNext()) {
			
			EEServiceUserRequest req = (EEServiceUserRequest) reqitr.next();
			selectedRequestMap.put(req.getEeServiceRequestLite().getEntityKey().getKeyValueAsString(), req.getEeServiceRequestLite().getName());
		}
		
	}
	public String[] getSelectedRequests() {
		return selectedRequests;
	}
	public void setSelectedRequests(String[] selectedRequests) {
		this.selectedRequests = selectedRequests;
	}	
}
