package br.mp.mprj.portal.portlet.gestaomensagens.util;

import java.util.concurrent.Callable;

import javax.portlet.PortletRequest;
import javax.portlet.PortletURL;

import br.mp.mprj.portal.portlet.gestaomensagens.action.ExcluirEmailDestinatarioActionCommand;

import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.Company;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.Layout;
import com.liferay.portal.service.CompanyLocalServiceUtil;
import com.liferay.portal.service.GroupLocalServiceUtil;
import com.liferay.portal.service.LayoutLocalServiceUtil;
import com.liferay.portal.service.persistence.CompanyUtil;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.PortalUtil;
import com.liferay.portlet.PortletURLFactoryUtil;
import com.liferay.util.ContentUtil;
import com.liferay.util.portlet.PortletRequestUtil;


public class GerarLink  {

	
	public static String call(PortletRequest portletRequest) {
		// TODO Auto-generated method stub

		String url = "/jsp/excluir-usuario.jsp";		
				
		String portletName = (String)portletRequest.getAttribute(WebKeys.PORTLET_ID);
		
		ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

		PortletURL redirectURL = PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(portletRequest),portletName,themeDisplay.getLayout().getPlid(), PortletRequest.RENDER_PHASE);

		redirectURL.setParameter("mvcPath", url);
							
		return redirectURL.toString();
	}

	public static String call() throws Exception {

    
      	Company company = CompanyLocalServiceUtil.getCompanyByMx(PropsUtil.get(PropsKeys.COMPANY_DEFAULT_WEB_ID));
      	
      	long groupId = company.getGroup().getGroupId(); 
      	
      	Group currentGroup = GroupLocalServiceUtil.getGroup(groupId);
      	
      	String hostHomol = null;
      	String hostProducao = null;
      	String url;
      	String serverId =  EmailUtil.getURLServidor(company.getCompanyId(), groupId); 
      	
//      	if(currentGroup.getExpandoBridge().getAttribute("HOST_NAME_ID_PRODUCAO").){
//      		
//      		hostProducao = currentGroup.getExpandoBridge().getAttribute("HOST_NAME_ID_PRODUCAO").toString();
//	  		url = hostProducao + "/cadastro/-/gestao/descadastrar";
//	  		
//	  	}else if((boolean) currentGroup.getExpandoBridge().getAttribute("HOST_NAME_ID")){
//	  		
//	      		hostHomol = currentGroup.getExpandoBridge().getAttribute("HOST_NAME_ID").toString();
//	      		if(serverId.contains("rj")){
//	      			serverId = "consumidorvencedor-rj";
//	      		}else{
//	      			String parts[] = serverId.split(".");
//	      			serverId = parts[0];
//	      		}	      		
//	      		url = hostHomol + serverId + "/cadastro/-/gestao/descadastrar";
//	      		
//	  	}else{
//	  		
//	      		url = "http://consumidorvencedor.mp.br";
//	      	
//	  	}     	
		
		return  currentGroup.getExpandoBridge().getAttribute("HOST_NAME_ID").toString();
	}

}
