package com.fitbank.web;

import java.sql.Date;

import com.fitbank.common.helper.FormatDates;
import com.fitbank.common.logger.FitbankLogger;
import com.fitbank.dto.management.Detail;
import com.fitbank.dto.management.Record;
import com.fitbank.dto.management.Table;
import com.fitbank.uci.client.UCIClient;

public class BussinessDelegate {
    public Detail process(Detail pDetail) throws Exception{
    	 pDetail.setResponse(null);
    	 Table tbl=pDetail.findTableByAlias("EXCHANGE");
    	 boolean remove=true;
    	 if(tbl!=null){
    		 for (Record rec : tbl.getRecords()) {
					if(rec.findFieldByNameCreate("VALORMONEDACUENTA").getRealValue()!=null){
						remove=false;
						break;
					}
    		 }
				}else{
					remove=false;
				}
    	 if(remove)
    	   pDetail.removeTable("EXCHANGE");    	
    	 long ini=System.currentTimeMillis();
    	 Detail det=UCIClient.send(pDetail);
    	 if(remove&&det.findTableByAlias("EXCHANGE")==null){
    		 det.addTable(tbl);
    	 }
    	 FitbankLogger.getLogger().info("Tiempo de Respuesta del mensaje "+det.getMessageid()+" "+FormatDates.getInstance().getTimeCountFormat().format(new Date(System.currentTimeMillis()-ini)));
        return det;
    }
             
}
