package com.ejie.m62fb.dao.registroVPP;

import com.ejie.m62fb.dao.SQLGenericas;
import com.ejie.m62fb.utils.constants.BDConstantes;

public class ElementosDaoSql {

	/**
	 * StringBuilder initilization value
	 */
	public static final int STRING_BUILDER_INIT = 4096;
	public static final String SEQUENCE_NAME = "";

	public static final String TABLA = BDConstantes.ELEMENTO;

	public static final String PK = "IDE_ELEMENTO";

	public static final String SQL_INSERT = "INSERT INTO"
			+ TABLA
			/* 5 */+ "(COD_TIPO_ELEM, COD_ELEMENTO, NUM_FIJO_IBI_ELEM,SUP_UTIL_ELEM, IND_USO_INDIV,NUM_VIVIENDA, "
			+ "COD_VINCUL_ELEM, NUM_EXPEDIENTE, NOM_REGISTRO_PROP,NUM_REGISTRO_PROP,"
			+ " DES_TOMO, DES_LIBRO, DES_FOLIO, DES_FINCA, DES_INSCRIPCION,FEC_ESCRITURA_SUEL,DES_cALLE"
			+ SQLGenericas.INSERT_DIRECCION_CLASS_SQL
			+ SQLGenericas.INSERT_ABSTRACT_CLASS_SQL + ") "
			+ "VALUES (?,?,?,?,?,?,?," + "?,?,?,?," + "?,?,?,?,?,?"
			+ SQLGenericas.INSERT_DIRECCION_CLASS_QUESTION_TAGS
			+ SQLGenericas.INSERT_ABSTRACT_CLASS_QUESTION_TAGS + ")";

	public static final String SQL_UPDATE = "UPDATE " + TABLA + " SET "
	/* 6 */+ "COD_TIPO_ELEM=? ,COD_ELEMENTO=?, NUM_FIJO_IBI_ELEM=?, SUP_UTIL_ELEM=?, " +
	 "IND_USO_INDIV=?,NUM_VIVIENDA=?, COD_VINCUL_ELEM=?, NUM_EXPEDIENTE=?, NOM_REGISTRO_PROP=?, NUM_REGISTRO_PROP=?, DES_TOMO=?, DES_LIBRO=?, "
	  + "DES_FOLIO=?, DES_FINCA=?, DES_INSCRIPCION=?, FEC_ESCRITURA_SUEL=?,DES_cALLE=?"
	 + SQLGenericas.UPDATE_DIRECCION_CLASS_SQL+ SQLGenericas.UPDATE_ABSTRACT_CLASS_SQL + "WHERE IDE_ELEMENTO=?";

	public static final String SQL_DELETE = "DELETE FROM " + TABLA
			+ " WHERE IDE_ELEMENTO = ?";

	public static final String SQL_SELECT = "SELECT "
			/* 6 */+ "IDE_ELEMENTO, COD_TIPO_ELEM, COD_ELEMENTO, NUM_FIJO_IBI_ELEM, SUP_UTIL_ELEM, "
			/* 6 */+ "IND_USO_INDIV, COD_VINCUL_ELEM, NUM_VIVIENDA, FEC_INI_GESTION, FEC_FIN_GESTION, NUM_ORGANO_GESTOR, "
			/* 6 */+ "FEC_ENV_ORG_GESTOR, NUM_EXPEDIENTE, NOM_REGISTRO_PROP, NUM_REGISTRO_PROP, DES_TOMO, DES_LIBRO, "
			/* 5 */+ "DES_FOLIO, DES_FINCA, DES_INSCRIPCION, FEC_ESCRITURA_SUEL,COD_REF_CATASTRAL"
			+ SQLGenericas.getSqlCamposDireccion(null)
			+ SQLGenericas.getSqlCamposAbstractClass(null);

	public static final String SQL_SELECT_COUNT = "SELECT COUNT(1)";

	public static final String SQL_FROM = " FROM " + TABLA;

	public static final String SQL_WHERE_ALL = " WHERE 1=1 ";

	public static final String SQL_WHERE_ID = SQL_WHERE_ALL + " AND "
			+ "IDE_ELEMENTO = ?";

	public static final String SQL_WHERE_ID_SIMPLE = " WHERE "
			+ "IDE_ELEMENTO = ?";
	public static final String SQL_WHERE_FOR_UPDATE = SQL_WHERE_ID
			+ " AND FEH_ULT_MODIF = ?";

	public static final String SQL_FIND_FOR_UPDATE = SQL_SELECT + SQL_FROM
			+ SQL_WHERE_FOR_UPDATE;

	public static final String SQL_FIND = SQL_SELECT + SQL_FROM + SQL_WHERE_ID;

	public static final String SQL_FIND_ALL = SQL_SELECT + SQL_FROM;

	public static final String SQL_FIND_ALL_COUNT = SQL_SELECT_COUNT + SQL_FROM;
	
	public static final String SQL_COUNT_CONTRATOS ="Select Count(1) FROM " + BDConstantes.CONTRATO_ALQUILER_ELEMENTO + " WHERE IDE_ELEMENTO = ?";
	
	public static final String SQL_DESVINCULAR_ELEMENTO ="UPDATE " + BDConstantes.ELEMENTO + " SET NUM_VIVIENDA = NULL " 
	+ SQLGenericas.UPDATE_ABSTRACT_CLASS_SQL + " WHERE IDE_ELEMENTO = ? AND NUM_VIVIENDA = ? ";
	
	public static final String SQL_VINCULAR_ELEMENTO ="UPDATE " + BDConstantes.ELEMENTO + " SET NUM_VIVIENDA = ? " + SQLGenericas.UPDATE_ABSTRACT_CLASS_SQL + " WHERE IDE_ELEMENTO = ?";

	private static final String SQL_WHERE_BY_VIVIENDA_AND_TIPO = SQL_WHERE_ALL
			+ " AND NUM_VIVIENDA = ?" + " AND COD_TIPO_ELEM = ? ";

	public static final String SQL_FIND_BY_VIVIENDA_AND_TIPO = SQL_SELECT
			+ SQL_FROM + SQL_WHERE_BY_VIVIENDA_AND_TIPO;
}