//
// 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.component;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import it.ramecera.salad.everyday.Candies;
import it.ramecera.salad.everyday.ExactException;
import it.ramecera.salad.everyday.Mix;
import it.ramecera.screwdriver.CandyScrew;
import it.ramecera.screwdriver.Cst;
import it.ramecera.screwdriver.Markup;
import it.ramecera.screwdriver.Skill;
import it.ramecera.screwdriver.Train;
import it.ramecera.screwdriver.outfits.TableOutfit;

/**
 * <p>
 * Creation date: 2020-04-09<br>
 * Last updated: 2020-06-20<br>
 * Company: Ramecera™
 * </p>
 * 
 * @author Massimo Maglioni
 *         <p>
 *         Description:
 *         </p>
 */
final public class JspFormImpl_java extends FileComponent {

	/** @param skill application main data
	 * @param snippetG name of the file containing the snippet */
	public JspFormImpl_java(Skill skill, String snippetG) {
		super();
		this.skill = skill;
		this.snippetG = snippetG;
	}

	/** @throws ExactException exception specified by a numeric code */
	@Override
	public void synthesis(HashMap<String, Markup> markupE,
			List<Train> trainE, CandyScrew candyScrew)

			throws FileNotFoundException, IOException, ExactException {

		producedMaterial = "";
		producedMaterial += "package " + skill.pckg + ".web.model."
				+ jspKit.path + ";" + Candies.LF + Candies.LF;
		for (int i = 0; i < jspKit.methodE.size(); i++) {
			String nomeMetodo = jspKit.methodE.get(i).text;
			for (int j = 0; j < skill.methodE.get(nomeMetodo).tableE
					.size(); j++) {
				TableOutfit t = skill.methodE.get(nomeMetodo).tableE
						.get(j);
				producedMaterial += "import " + skill.pckg + "."
						+ t.railLowercase + ".dao.I" + Mix
								.uppercaseFirstChar(t.railLowercase)
						+ t.entityName + "Dao;" + Candies.LF;
				producedMaterial += "import " + skill.pckg + "."
						+ t.railLowercase + ".dao.impl." + Mix
								.uppercaseFirstChar(t.railLowercase)
						+ t.entityName + "Dao;" + Candies.LF;
			}
		}
		producedMaterial += "import org.springframework.stereotype.Component;"
				+ Candies.LF;
		producedMaterial += Candies.LF
				+ "import javax.servlet.http.HttpServletRequest;"
				+ Candies.LF;
		if (skill.log4jVers != null) {
			producedMaterial += Candies.LF
					+ "import org.apache.log4j.Logger;" + Candies.LF
					+ Candies.LF;
		}
		producedMaterial += "@Component" + Candies.LF;
		producedMaterial += "public class " + jspKit.nomeFileU
				+ Cst.FORMU + "Impl extends " + jspKit.nomeFileU
				+ Cst.FORMU + " {" + Candies.LF + Candies.LF;
		if (skill.log4jVers != null) {
			producedMaterial += Candies.TABS + "/** ordinary logger */"
					+ Candies.LF;
			producedMaterial += Candies.TABS
					+ "@SuppressWarnings(\"unused\")" + Candies.LF;
			producedMaterial += Candies.TABS
					+ "private static final Logger logger = Logger.getLogger("
					+ Candies.LF + Candies.TABS + Candies.TABS
					+ Candies.TABS + jspKit.nomeFileU + Cst.FORMU
					+ "Impl.class);" + Candies.LF + Candies.LF;
		}
		for (int i = 0; i < jspKit.methodE.size(); i++) {
			String nomeMetodo = jspKit.methodE.get(i).text;
			producedMaterial += Candies.TABS + "@Override" + Candies.LF;
			producedMaterial += Candies.TABS + "public void "
					+ nomeMetodo + "(";
			producedMaterial += "HttpServletRequest request";
			if (!skill.methodE.get(nomeMetodo).upperArguments.trim()
					.isEmpty()) {
				producedMaterial += ", ";
			}
			producedMaterial += skill.methodE.get(
					nomeMetodo).upperArguments;
			for (int cJ = 0; cJ < skill.methodE.get(nomeMetodo).classE
					.size(); cJ++) {
				producedMaterial += ", ";
				producedMaterial += skill.methodE.get(
						nomeMetodo).classE.get(cJ) + " other" + cJ;

			}
			producedMaterial += ") {" + Candies.LF + Candies.LF;
			if (skill.methodE.get(nomeMetodo).source != null) {
				producedMaterial += skill.methodE.get(
						nomeMetodo).source + Candies.LF;
			}
			producedMaterial += Candies.TAB + "}" + Candies.LF
					+ Candies.LF;
		}
		producedMaterial += "}" + Candies.LF;
	}

	/* written only to comply with the abstract class FileComponent */
	@SuppressWarnings("javadoc")
	@Override
	/** @param markupE the list of markups
	 * @param skill together with the characteristics of the application
	 * @param trash file where the deleted files are moved
	 * @throws ExactException exception specified by a numeric code */
	public void directory(HashMap<String, Markup> markupE)

			throws ExactException {

	}
}
