package com.strategyquant.extend.DatabankColumns;

import com.strategyquant.lib.databank.DatabankColumn;
import com.strategyquant.lib.language.L;
import com.strategyquant.lib.results.SQResult;
import com.strategyquant.lib.results.SQResultsGroup;
import com.strategyquant.lib.results.SQStats;
import com.strategyquant.lib.results.StatsConst;
import com.strategyquant.lib.results.StatsMissingException;
import com.strategyquant.lib.settings.SQConst;

public class Commission extends DatabankColumn {
    
	public Commission() {
		super();
		
		setName(L.t("Commission"));		
		setTooltip(L.t("Commission"));
		setWidth(60);
	}
	
	@Override
	public Object getValue(SQResultsGroup strategyResults, String dataType, String direction, String sampleType, String plType) throws Exception {
		SQResult result = strategyResults.getResult(SQConst.SYMBOL_PORTFOLIO);
		
		SQStats stats = result.getStats(direction, getGlobalPlType(plType), sampleType);
		if(stats==null) throw new StatsMissingException();
		
		return stats.getDouble(StatsConst.COMMISSION);
	}
	
	@Override
	public String displayString(SQResultsGroup strategyResults, String dataType, String direction, String sampleType, String plType) throws Exception {
		Double comm = (Double) getValue(strategyResults, dataType, direction, sampleType, plType);
		
		return twoDecimalFormatWithPlType(comm, SQConst.PL_IN_MONEY);
	}
	
	@Override
	public String exportString(SQResultsGroup strategyResults, String dataType, String direction, String sampleType, String plType) throws Exception {
		Double comm = (Double) getValue(strategyResults, dataType, direction, sampleType, plType);
		
		return twoDecimalFormat(comm);		
	}
}