<?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.minimum.daos.MinimunDAO">
		
	  <resultMap type='MinimunDTO' id='minimunResult'>	    
	    <id     property='idMinimun'   column='ID_MINIMUM'/>
	    <result property='idContrato'  column='ID_CONTRATO'/>
	    <result property='idPais'      column='ID_PAIS'/>
	    <result property='idRealese'   column='ID_RELEASE'/>	    
	    <result property='idFormato'   column='ID_FORMATO'/>
	    <result property='monto'       column='MONTO'/>
	  </resultMap>
 
  	 <select id='getMinimunsXPais' resultMap='minimunResult' parameterType="map">
   		 
     		SELECT 
		       ID_MINIMUM, ID_CONTRATO, ID_PAIS, ID_RELEASE, ID_FORMATO, MONTO		       
		       FROM DDA_T_CONTRATO_MINIMUM
		       WHERE 
		            ID_CONTRATO = #{idContrato} AND          
		            ID_PAIS IN   		                   
			        <foreach item="id" index="index" collection="paises" open="(" separator="," close=")">
	            		#{id}
	        		</foreach>	        		             
		       ORDER BY ID_CONTRATO, ID_PAIS      		     		  			       		   		
	  </select>
	  
	 <insert id='agregarMinimun' parameterType="map">
	  		 INSERT ALL 	  		
	  		 <foreach item="id" index="index" collection="minimuns" >			  		  
	                  INTO DDA_T_CONTRATO_MINIMUM (ID_MINIMUM, ID_CONTRATO, ID_PAIS, ID_RELEASE, ID_FORMATO, MONTO) 
	                  VALUES (#{id.idMinimun}, #{id.idContrato}, #{id.idPais}, #{id.idRealese}, #{id.idFormato}, #{id.monto})
	         </foreach>
			 SELECT * FROM dual	            		
      </insert>
	  	  
	  <select id="getSecuenciaMinimun" resultType="java.lang.Long">	       	  		
		      SELECT DDA_SQT_CONTRATO_MINIMUM.nextVal from DUAL		  		
	  </select>
	  
	  <update id="actualizarMinimun" parameterType="map">	          	  		
	  		 <foreach item="id" index="index" collection="minimuns" >			  		  
	                  UPDATE DDA_T_CONTRATO_MINIMUM SET MONTO = #{id.monto} WHERE ID_MINIMUM =  #{id.idMinimun}
	         </foreach>			 
	  </update>
	  	  
</mapper>