//
// 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.salad.everyday.Strings;
import it.ramecera.salad.file.Equipment;
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;

/**
 * <p>
 * This class is used for the following components: headerJsp,
 * footerJsp, genericRailDaoImplJPAx, tiles_xml, service_xml, orm_xml,
 * doorControllerBelong_java, genericCrud_java, controllerBelong_java,
 * jspForm_java, jspPlain_ java, Xtajut user , quartzTask_java,
 * quartzTaskImpl_java
 * </p>
 * <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 Hoof extends FileComponent {

	/** @param skill together with the descriptive data of the
	 * @param snippetG application */
	public Hoof(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 {

		String g = skill.candies.snippetsYS + snippetG;
		producedMaterial = Equipment.oneString(g) + Candies.LF;

		/* WE COOK EVERYTHING */
		if (skill.pckg != null) {
			producedMaterial = producedMaterial.replaceAll(
					"\\x2bzoccolo\\x2b", skill.pckg);
		}
		if (skill.applicationNameLower != null) {
			producedMaterial = Strings.replaceFirst(producedMaterial,
					"+titolo+", skill.applicationNameLower);
		}
		if (skill.quartzVers != null) {
			producedMaterial = producedMaterial.replaceAll(
					"\\x2bQuartzjob\\x2b", skill.clockHands.jobNameU);
			producedMaterial = producedMaterial.replaceAll(
					"\\x2bQuartztask\\x2b", skill.clockHands.taskNameU);
		}
		if (skill.hasUseridPassword) {
			producedMaterial = Strings.replaceFirst(producedMaterial,
					"+tabposition+", (skill.networkDomain
							+ ".screwdriver." + skill.tabUser[2] + "."
							+ skill.tabUser[3]).toLowerCase());
			if (skill.authenticationMode.equals("trivial")) {
				producedMaterial = Strings.replaceFirst(
						producedMaterial, "+beanposition+", skill.pckg
								+ ".domain");
			} else {
				producedMaterial = Strings.replaceFirst(
						producedMaterial, "+beanposition+",
						(skill.networkDomain + ".screwdriver."
								+ skill.tabUser[2] + "."
								+ skill.tabUser[3]).toLowerCase());
			}
			if (producedMaterial.indexOf("+tabella+") > -1) {
				producedMaterial = producedMaterial.replaceAll(
						"\\x2btabella\\x2b", skill.tabUser[0]);
			}
			if (producedMaterial.indexOf("+bean+") > -1) {
				if (skill.authenticationMode.equals("trivial")) {
					producedMaterial = producedMaterial.replaceAll(
							"\\x2bbean\\x2b", "King");
				} else {
					producedMaterial = producedMaterial.replaceAll(
							"\\x2bbean\\x2b", skill.tabUser[0]);
				}
			}
			if (producedMaterial.indexOf("+userrail+") > -1) {
				producedMaterial = producedMaterial.replaceAll(
						"\\x2buserrail\\x2b", Cst.RAIL
								+ skill.tabUser[1]);
			}
			if (producedMaterial.indexOf("+Userrail+") > -1) {
				producedMaterial = producedMaterial.replaceAll(
						"\\x2bUserrail\\x2b", Cst.RAILU
								+ skill.tabUser[1]);
			}
			producedMaterial = Strings.replaceFirst(producedMaterial,
					"+password+", Mix.uppercaseFirstChar(
							skill.password));
		}
		if (markupE.get("hdefrail").recurrenceE.size() > 0) {
			Train f = markupE.get("hdefrail").recurrenceE.get(
					skill.railK);
			producedMaterial = producedMaterial.replaceAll(
					"\\x2brail\\x2b", Cst.RAIL + f.locomotor.text);
			producedMaterial = producedMaterial.replaceAll(
					"\\x2bRail\\x2b", Cst.RAILU + f.locomotor.text);
		}

		if (markupE.get("usignup").recurrenceE.size() > 0) {
			String t = "";
			t += Candies.TABS + "@RequestMapping(\"/signup/form\")"
					+ Candies.LF;
			t += Candies.TABS + "public String nuovoUtente() {"
					+ Candies.LF;
			t += Candies.TABS + Candies.TABS + "return \"home/signup\";"
					+ Candies.LF;
			t += Candies.TABS + "}" + Candies.LF;
			producedMaterial = Strings.replaceFirst(producedMaterial,
					"+signup+", t);
		} else {
			producedMaterial = Strings.replaceFirst(producedMaterial,
					"+signup+", "");
		}
	}

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

			throws ExactException {

	}
}
