package com.fp.armas.rules.save.armas;

import java.util.List;

import com.fp.dto.rules.TransactionRule;
import com.fp.dto.save.SaveRequest;
import com.fp.persistence.parmas.soli.TarmArmas;
import com.fp.sessionbeans.helper.Sequence;

public class AuxCodigoArma extends TransactionRule {

	private static final long serialVersionUID = -7465655492847129136L;

	@Override
	public SaveRequest normalProcess(SaveRequest pSaveRequest) throws Exception {
		//lista de armas
		 List<Object> listArmas = pSaveRequest.getSaveBeanModifiedRecords("AUXARMAS");
		 for (Object object : listArmas) {
			 TarmArmas arma = (TarmArmas)object;
			 arma.setPk(getCodigoArma());
		}
    	
		return pSaveRequest;
	}

	@Override
	public SaveRequest reverseProcess(SaveRequest pRequest) throws Exception {
		return pRequest;
	}
	
	
	private String getCodigoArma() throws Exception{
		Sequence sequence = new Sequence();
		String carma = sequence.getNextValue("CARMA").toString();
		return carma;
	}
}
