package com.fp.armas.rules.query.solicitud;

import java.util.List;

import com.fp.bpm.query.QueryJsf;
import com.fp.dto.query.QueryRequest;
import com.fp.dto.rules.QueryRule;
import com.fp.persistence.commondb.PersistenceHelper;
import com.fp.persistence.parmas.param.TarmCentroControl;
import com.fp.persistence.parmas.soli.TarmSolicitudArmas;
import com.fp.persistence.parmas.soli.TarmSolicitudDocumento;
import com.fp.persistence.pgeneral.gene.TgeneProvince;
import com.fp.persistence.pgeneral.gene.TgeneProvinceKey;

public class CompletaInfoVerificarDocumentos extends QueryRule{

	@SuppressWarnings("unchecked")
	@Override
	public QueryRequest process(QueryRequest pQueryRequest) throws Exception {
		QueryJsf qry = new QueryJsf();
		qry.execute(pQueryRequest);
		
		List<Object> datos = (List<Object>)pQueryRequest.getResponse().get("VERIFICARDOCUMENTOS");//VERIFICARDOCUMENTOS
		if(datos!=null){
			for(Object dato : datos){
				TarmSolicitudDocumento sol = (TarmSolicitudDocumento)dato;
				String centroControl =(String)sol.modifiedData.get("ccentrocontrol");
				if(centroControl != null){
					TarmCentroControl cControl = TarmCentroControl.find(PersistenceHelper.getEntityManager(), centroControl);
					if(cControl !=  null){
						TgeneProvinceKey key = new TgeneProvinceKey();
						key.setCountrycode(cControl.getCountrycode());
						key.setProvincecode(cControl.getProvincecode());
						TgeneProvince province = TgeneProvince.find(PersistenceHelper.getEntityManager(), key);
						sol.modifiedData.put("ubicaciondesc", province.getDescription());
					}
				}
				
				
			}
		}
		return pQueryRequest;
	}

}
