package db;

import java.util.LinkedHashMap;
import java.util.Map;

public class ManageTable {
	
	public final static Map<String, String> create = new LinkedHashMap<>();
	public final static Map<String, String> drop = new LinkedHashMap<>();	
	static {
		iniCreate();
		iniDrop();
	}
	
	private static void iniCreate() {
		create.put("Espace", "CREATE TABLE Espace ("
				+ "ID BIGINT NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY,"
				+ "LIBELLE VARCHAR(250) NOT NULL)");
		create.put("Ville", "CREATE TABLE Ville ("
				+ "ID BIGINT NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY,"
				+ "LIBELLE VARCHAR(250) NOT NULL,"
				+ "CODEPOSTAL VARCHAR(5))");
		create.put("Niveau", "CREATE TABLE Niveau ("
				+ "ID BIGINT NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY,"
				+ "LIBELLE VARCHAR(250) NOT NULL)");
		create.put("Ecole", "CREATE TABLE Ecole ("
				+ "ID BIGINT NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY,"
				+ "LIBELLE VARCHAR(250) NOT NULL,"
				+ "VILLE BIGINT REFERENCES Ville(ID),"
				+ "NIVEAU BIGINT REFERENCES Niveau(ID))");
		create.put("Usager", "CREATE TABLE Usager ("
				+ "ID BIGINT NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY,"
				+ "NOM VARCHAR(250) NOT NULL,"
				+ "PRENOM VARCHAR(250) NOT NULL,"
				+ "DATEDENAISSANCE DATE NOT NULL,"
				+ "EMAIL VARCHAR(250) NOT NULL,"
				+ "TELEPHONE VARCHAR(12) NOT NULL,"
				+ "CONTACTURGENCE VARCHAR(250) NOT NULL,"
				+ "CODE VARCHAR(4) NOT NULL,"
				+ "SCOLAIRE BOOLEAN NOT NULL,"
				+ "DESCRIPTION VARCHAR(250) NOT NULL,"
				+ "VILLE BIGINT REFERENCES Ville(ID),"
				+ "ECOLE BIGINT REFERENCES Ecole(ID))");
		create.put("Frequentation", "CREATE TABLE Frequentation ("
				+ "ESPACE BIGINT REFERENCES Espace(ID),"
				+ "USAGER BIGINT REFERENCES Usager(ID),"
				+ "DATE DATE NOT NULL,"
				+ "PRIMARY KEY(ESPACE, USAGER))");
	}
	
	private static void iniDrop() {
		drop.put("Frequentation", "DROP TABLE Frequentation");
		drop.put("Usager", "DROP TABLE Usager");
		drop.put("Ecole", "DROP TABLE Ecole");
		drop.put("Niveau", "DROP TABLE Niveau");
		drop.put("Ville", "DROP TABLE Ville");
		drop.put("Espace", "DROP TABLE Espace");
	}

}
