package kr.co.i4way.genesys.config;

import java.util.Collection;

import com.genesyslab.platform.applicationblocks.com.ConfigException;
import com.genesyslab.platform.applicationblocks.com.IConfService;
import com.genesyslab.platform.applicationblocks.com.objects.CfgAgentGroup;
import com.genesyslab.platform.applicationblocks.com.objects.CfgPerson;
import com.genesyslab.platform.applicationblocks.com.queries.CfgAgentGroupQuery;
import com.genesyslab.platform.applicationblocks.com.queries.CfgPersonQuery;

public class AgentGroup {
	
	public AgentGroup(){
	}
	
	/**
	 * AgentGroup을 조회한다.
	 * @param iTenantDBID
	 * @param service 
	 * @return
	 * @throws ConfigException
	 * @throws InterruptedException
	 */
	public Collection<CfgAgentGroup> SelectAgentGroup(
			int iTenantDBID,
			final IConfService service)
					throws ConfigException, InterruptedException {
		// Read configuration objects:
		CfgAgentGroupQuery agentgroupquery = new CfgAgentGroupQuery();
		agentgroupquery.setTenantDbid(iTenantDBID);
		Collection<CfgAgentGroup> agentgroups = service.retrieveMultipleObjects(CfgAgentGroup.class,
				agentgroupquery);

		return agentgroups;
	}
	
	/**
	 * AgentGroup을 조회한다.
	 * @param iTenantDBID
	 * @param sEmployeeId
	 * @param service
	 * @return
	 * @throws ConfigException
	 * @throws InterruptedException
	 */
	public Collection<CfgAgentGroup> SelectAgentGroup(
			int iTenantDBID,
			String sGroupName,
			final IConfService service)
					throws ConfigException, InterruptedException {
		// Read configuration objects:
		CfgAgentGroupQuery agentgroupquery = new CfgAgentGroupQuery();
		agentgroupquery.setTenantDbid(iTenantDBID);
		agentgroupquery.setName(sGroupName);
		Collection<CfgAgentGroup> agentgroups = service.retrieveMultipleObjects(CfgAgentGroup.class,
				agentgroupquery);

		return agentgroups;
	}
	
	public CfgAgentGroup SelectAgentGroup(
			int iTenantDBID,
			int iDbid,
			final IConfService service)
					throws ConfigException, InterruptedException {
		// Read configuration objects:
		CfgAgentGroup rtnAgentGroup = null;
		CfgAgentGroupQuery agentgroupquery = new CfgAgentGroupQuery();
		agentgroupquery.setTenantDbid(iTenantDBID);
		agentgroupquery.setDbid(iDbid);
		Collection<CfgAgentGroup> agentgroups = service.retrieveMultipleObjects(CfgAgentGroup.class,
				agentgroupquery);
		for(CfgAgentGroup agentgroup : agentgroups){
			rtnAgentGroup = agentgroup;
		}

		return rtnAgentGroup;
	}
	

	public Collection<CfgPerson> SelectPersonInGroup(
			int iTenantDBID,
			int iGroupDBID,
			final IConfService service)
					throws ConfigException, InterruptedException {
		// Read configuration objects:
		CfgPersonQuery personquery = new CfgPersonQuery();
		personquery.setTenantDbid(iTenantDBID);
		personquery.setGroupDbid(iGroupDBID);
		Collection<CfgPerson> persons = service.retrieveMultipleObjects(CfgPerson.class,
				personquery);

		return persons;
	}
	

}
