<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.mx.dla.dda.contrato.deal.daos.DealDAO">

	<resultMap id="resultsTransTypeByContract" type="TypeDTO">
		<result property="idType" column="ID_TYPE" />
		<result property="descType" column="DESC_TYPE" />	
		<result property="estatus" column="ESTATUS" />
	</resultMap>
	
	<resultMap id="resultsTransType" type="TypeDTO">	
		<result property="idType" column="ID_TYPE" />
		<result property="descType" column="DESC_TYPE" />	
		<result property="estatus" column="ESTATUS" />
	</resultMap>
	
	<insert id="creaContratoTypeRelacion" parameterType="ContratoTypeDTO" >

		INSERT INTO DDA_T_CONTRATO_DEAL_TYPE 
		  (ID_CONTRATO, ID_TYPE) 
		     values(
		        #{idContrato, javaType=Long, jdbcType=NUMERIC},
		        #{idType, javaType=Long, jdbcType=NUMERIC}
		      )    
	</insert>

	<select id="consultaDealTypesByContrato"  resultMap="resultsTransTypeByContract" 
		parameterType="map">
		SELECT 
           tp.ID_TYPE, 
           tp.DESC_TYPE, 
           tp.ESTATUS 
        FROM DDA_T_CONTRATO_DEAL_TYPE cdt
          INNER JOIN DDA_C_TYPE tp
          ON tp.ID_TYPE = cdt.ID_TYPE
        WHERE 
           cdt.ID_CONTRATO = #{contratoType.idContrato}
        AND 
           tp.ESTATUS = 1
	</select>
	
	<select id="consultaDealTypes" resultMap="resultsTransType"
		parameterType="map">
        SELECT 
           tp.ID_TYPE, 
           tp.DESC_TYPE, 
           tp.ESTATUS 
        FROM DDA_C_TYPE tp 
	</select>
	
	<delete id="eliminaContratoTypeRelacion" parameterType="ContratoTypeDTO">
		DELETE DDA_T_CONTRATO_DEAL_TYPE
		WHERE
		    ID_CONTRATO = #{idContrato, javaType=Long, jdbcType=NUMERIC}
		    AND
		    ID_TYPE = #{idType, javaType=Long, jdbcType=NUMERIC}
	</delete>

</mapper>