package com.javahonk.fix.mediator;

import java.util.ArrayList;

import quickfix.Session;
import quickfix.SessionID;
import quickfix.fix42.ExecutionReport;

import com.javahonk.fix.adapter.PhysicalSettlementAdapter;
import com.javahonk.fix.adapter.PhysicalSettlementAdapterImpl;
import com.javahonk.fix.model.LifeCycleManagerModel;
import com.javahonk.fix.test.FixInitiatorStratup;

public class PhysicalSettlementMediatorImpl implements
		PhysicalSettlementMediator {

	@Override
	public ExecutionReport sendPhysicalSettlementOrder(LifeCycleManagerModel lifeCycleManagerModel) {
		
		try {

			ArrayList<SessionID> sessions = FixInitiatorStratup.getFixSession();
			
			PhysicalSettlementAdapter fixMessageAdapter = new PhysicalSettlementAdapterImpl();

			SessionID sessionID = sessions.get(0);
			System.out.println("Sending Order to Server");
			Session.sendToTarget(fixMessageAdapter.convertNewOrderSingle(lifeCycleManagerModel), sessionID);
			Thread.sleep(3000);
			System.out.println("Stoping socketInitiator");
			FixInitiatorStratup.stopFixInitiator();

		} catch (Exception e) {
			e.printStackTrace();
		}
		return FixInitiatorStratup.getExecutionReport();

	}

}
