package com.bitgate.nucleus.render;

import com.bitgate.nucleus.render.tag.DocumentTag;
import com.bitgate.nucleus.util.VariableStore;

/**
 * This is a storage bean class that is used to keep track of an actively rendered document.  It is used by the
 * {@link DocumentTag}.
 */
public class RenderContext {

  private String contentType;
  private String uri;
  private String path;
  private VariableStore variableStore;
  private VariableStore formVariableStore;
  private RenderMode renderMode;

  /**
   * Indicates the rendering mode.
   */
  public enum RenderMode {
    /** Indicates that a render is being done live, and not as the body of a variable. */
    LIVE,

    /** Indicates that a render is taking place within a sub-tag inside the document. */
    INLINE
  }

  /**
   * Constructor.
   */
  public RenderContext() {
    this.contentType = "text/html";
    this.uri = null;
    this.path = null;
    this.variableStore = new VariableStore();
    this.formVariableStore = new VariableStore();
    this.renderMode = RenderMode.LIVE;
  }

  /**
   * Constructor, copies the current set of {@link VariableStore} objects, used for inline rendering.
   *
   * @param store {@link VariableStore} of variables.
   */
  public RenderContext(VariableStore store) {
    this.contentType = "text/html";
    this.uri = null;
    this.path = null;
    this.variableStore = new VariableStore(store.getStore());
    this.formVariableStore = new VariableStore();
    this.renderMode = RenderMode.INLINE;
  }

  /**
   * Retrieves the current content type.
   *
   * @return {@link String} containing the content type.
   */
  public String getContentType() {
    return contentType;
  }

  /**
   * Sets the current content type.
   *
   * @param contentType {@link String} containing the content type.
   */
  public void setContentType(String contentType) {
    this.contentType = contentType;
  }

  /**
   * Retrieves the URI of the original request.
   *
   * @return {@link String} containing the original request URI.
   */
  public String getUri() {
    return uri;
  }

  /**
   * Sets the URI of the original request.
   *
   * @param uri {@code String} containing the URI, {@code null} indicates inline content.
   */
  public void setUri(String uri) {
    this.uri = uri;
  }

  /**
   * Retrieves the path to the content being rendered.
   *
   * @return {@link String} containing the path of the content.
   */
  public String getPath() {
    return path;
  }

  /**
   * Sets the path for the content being rendered.
   *
   * @param path {@code String} containing the path; {@code null} indicates inline content.
   */
  public void setPath(String path) {
    this.path = path;
  }

  /**
   * Retrieves the current {@link VariableStore}.
   *
   * @return Current {@link VariableStore} object.
   */
  public VariableStore getVariableStore() {
    return variableStore;
  }

  /**
   * Retrieves the current {@link VariableStore} for GET variables that were posted.
   *
   * @return Current {@link VariableStore} object containing GET variables.
   */
  public VariableStore getFormVariableStore() {
    return formVariableStore;
  }

  /**
   * Retrieves the current rendering mode.
   *
   * @return {@link RenderMode}
   */
  public RenderMode getRenderMode() {
    return renderMode;
  }

  /**
   * Sets the current render mode.
   *
   * @param renderMode {@link RenderMode} to set.
   */
  public void setRenderMode(RenderMode renderMode) {
    this.renderMode = renderMode;
  }
}
