//
// https://www.ramecera.it/myscrewdriver.html
// e-mail: screwdriver@ramecera.it
//
/* This program and the accompanying materials are made available under
 * the terms of the Eclipse Public License v1.0 which accompanies this
 * distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html */
package it.ramecera.screwdriver.outfits;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import it.ramecera.salad.everyday.Candies;
import it.ramecera.salad.everyday.Mix;
import it.ramecera.salad.graphic.Placard;
import it.ramecera.screwdriver.Cst;
import it.ramecera.screwdriver.Wagon;

/**
 * <p>
 * Elements forming a JSP.
 * </p>
 * <p>
 * Company: Ramecera™<br>
 * Creation date: 2020-04-09<br>
 * Last updated: 2020-04-09
 * </p>
 * <p>
 * Modifications:<br>
 * </p>
 * 
 * @author M. Maglioni */
final public class JspKit {

	/** the path, without final slash */
	public String path;
	/** the name of the file without extension and without final dot */
	public String fileName;
	/** the name of the file without extension and without final dot,
	 * first character uppercase */
	public String nomeFileU;
	/** the extension without the initial dot */
	public String extension;
	/** if I want the pragma feature */
	public boolean pragma;
	/** when the jsp is form, the list of controls */
	public List<JspBeanElement> controlE = new ArrayList<JspBeanElement>();
	/** together with the request-maps that lead to this JSP through the
	 * Spring controllers */
	public List<RequestMap> requestMapE = new ArrayList<RequestMap>();
	/** presence in the JSP of a navigation bar */
	public String navigationBar;
	/** navigation bar's Jsp kit */
	public MenuKit menuKit;
	/** type of JSP: 0 = plain; 1 = form; 2 = model */
	public int jspType;
	/** list of String properties of the JSP bean */
	public List<JspBeanElement> stringPropertyE = new ArrayList<JspBeanElement>();
	/** list of JSP bean ArrayList properties */
	public List<JspBeanElement> arrayStringPropertyE = new ArrayList<JspBeanElement>();
	/** list of Integer properties of the JSP bean */
	public List<JspBeanElement> integerPropertyE = new ArrayList<JspBeanElement>();
	/** list of Long type properties of the JSP bean */
	public List<JspBeanElement> longPropertyE = new ArrayList<JspBeanElement>();
	/** list of Boolean properties of the JSP bean */
	public List<JspBeanElement> booleanPropertyE = new ArrayList<JspBeanElement>();
	/** list of additional methods contained in the jsp bean */
	public List<Wagon> methodE = new ArrayList<Wagon>();
	/** placed in the list of trains */
	public int placeJ;
	/** the predominant CSS class in this JSP */
	public String classeCss;
	/** JSP refresh period, expressed in seconds */
	public int refresh;
	/** title of the page to be placed in the center, clearly visible */
	public String pageTitle;
	/** if it is a CRUD JSP, therefore with 4 buttons */
	public boolean crud;
	/** if it is a JSP that must be born on a new TAB */
	public boolean blank;
	/** legend parameter to show in the JSP */
	public String legend = "";

	/** ordinary logger */
	private static final Logger logger = Logger.getLogger(JspKit.class);

	/** default constructor */
	public JspKit() {

	}

	/**
	 * <p>
	 * Standard constructor.
	 * </p>
	 * <p>
	 * Creation date: 2020-04-09<br>
	 * Last updated: 2020-04-09
	 * </p>
	 * <p>
	 * Modifications:<br>
	 * </p>
	 * 
	 * @param path the path, without final slash
	 * @param fileName the name of the file without extension and
	 *        without final dot
	 * @param extension the extension without initial dot
	 * @param pragma if I want the pragma feature
	 * @param controlE if the jsp contains a form
	 * @param navigationBar name of the navigation bar to be inserted in
	 *        the JSP
	 * @param methodE list of methods present as source code java
	 * @param placeJ place of the JSP markup in the list of trains
	 * @param classeCss the predominant CSS class in this JSP
	 * @param refresh refresh period of the JSP, expressed in seconds */
	public JspKit(final String path, final String fileName,
			final String extension, final boolean pragma,
			List<JspBeanElement> controlE, final String navigationBar,
			List<Wagon> methodE, final int placeJ,
			final String classeCss, final int refresh) {
		super();
		if (path.startsWith("/")) {
			String message = "JSP " + path + "/" + fileName + "."
					+ extension + " path starts with a slash,"
					+ " it will be automatically removed.";
			logger.info(message);
			new Placard(null, message, "Notice");
			this.path = path.substring(1);
		} else {
			this.path = path;
		}
		this.fileName = fileName;
		this.nomeFileU = Mix.uppercaseFirstChar(fileName);
		this.extension = extension;
		this.pragma = pragma;
		this.controlE = controlE;
		this.navigationBar = navigationBar;
		this.methodE = methodE;
		this.placeJ = placeJ;
		this.classeCss = classeCss;
		this.refresh = refresh;
	}

	/**
	 * <p>
	 * Classic toString.
	 * </p>
	 * <p>
	 * Company: Ramecera™<br>
	 * Creation date: 2020-04-09<br>
	 * Last updated: 2020-04-09<br>
	 * </p>
	 * <p >
	 * Modifications:<br>
	 * </p>
	 * 
	 * @return the compound string */
	public String toString() {
		String s = Candies.LF + Cst.CUT3;
		s += "          * Path and file name=" + path + "/" + fileName
				+ "." + extension + Candies.LF;
		if (classeCss != null) {
			s += "          * CSS predominant className = " + classeCss
					+ Candies.LF;
		}
		if (legend != null && !legend.isEmpty()) {
			s += "          * legend = " + legend + Candies.LF;
		}
		if (crud) {
			s += "          * with CRUD" + Candies.LF;
		} else {
			s += "          * no CRUD" + Candies.LF;
		}
		if (blank) {
			s += "          * with blank command" + Candies.LF;
		}
		if (requestMapE.size() > 0) {
			s += "          * Request mappings list:" + Candies.LF;
			for (int i = 0; i < requestMapE.size(); i++) {
				RequestMap rm = requestMapE.get(i);
				s += "          * " + i + ") " + rm.toString();
			}
			s += Cst.CUT3;
		}
		if (stringPropertyE.size() > 0) {
			s += "          * Properties list of the linked bean:"
					+ Candies.LF;
			for (int i = 0; i < stringPropertyE.size(); i++) {
				JspBeanElement x = stringPropertyE.get(i);
				s += "          * " + i + ") " + x.toString()
						+ Candies.LF;
			}
			for (int i = 0; i < arrayStringPropertyE.size(); i++) {
				JspBeanElement x = arrayStringPropertyE.get(i);
				s += "          * " + i + ") (array)" + x.toString()
						+ Candies.LF;
			}
			s += Cst.CUT3;
		}
		s += Cst.CUT3;
		return s;
	}
}
