/**
 * This file is part of the Meeds project (https://meeds.io/).
 *
 * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
package org.gatein.pc.test.controller.unit;

import org.gatein.common.util.MarkupInfo;
import org.gatein.common.io.Serialization;
import org.gatein.pc.api.ContainerURL;
import org.gatein.pc.api.URLFormat;
import org.gatein.pc.controller.state.PageNavigationalState;
import org.gatein.pc.portlet.impl.spi.AbstractPortletInvocationContext;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

/**
 * An implementation of the <code>PortletInvocationContext</code> interface that is related to a specific
 * window.
 *
 */
public class ControllerPortletInvocationContext extends AbstractPortletInvocationContext
{

   /** . */
   private final PortletURLRenderer urlRenderer;

   /** . */
   private final String windowId;

   /** . */
   private final HttpServletRequest clientRequest;

   /** . */
   private final HttpServletResponse clientResponse;

   public ControllerPortletInvocationContext(
      Serialization<PageNavigationalState> serialization,
      HttpServletRequest clientRequest,
      HttpServletResponse clientResponse,
      String windowId,
      PageNavigationalState pageNavigationalState)
   {
      super();

      //
      this.clientRequest = clientRequest;
      this.clientResponse = clientResponse;
      this.windowId = windowId;
      this.urlRenderer = new PortletURLRenderer(pageNavigationalState, clientRequest, clientResponse, serialization);
   }

   public String getWindowId()
   {
      return windowId;
   }

   public HttpServletRequest getClientRequest() throws IllegalStateException
   {
      return clientRequest;
   }

   public HttpServletResponse getClientResponse() throws IllegalStateException
   {
      return clientResponse;
   }

   public String renderURL(ContainerURL containerURL, URLFormat format)
   {
      return urlRenderer.renderURL(windowId, containerURL, format);
   }
}
