#include "PulseLengthStatAnalyzerSettings.h"
#include <AnalyzerHelpers.h>

PulseLengthStatAnalyzerSettings::PulseLengthStatAnalyzerSettings()
	: mInputChannel(UNDEFINED_CHANNEL),
	  mInputChannelInterface()
{
	mInputChannelInterface.SetTitleAndTooltip(
		"Input",
		"Digital channel: one frame per stable level between edges (duration in samples / us).");
	mInputChannelInterface.SetChannel(mInputChannel);

	AddInterface(&mInputChannelInterface);

	AddExportOption(0, "Export as text/csv file");
	AddExportExtension(0, "text", "txt");
	AddExportExtension(0, "csv", "csv");

	ClearChannels();
	AddChannel(mInputChannel, "Input", false);
}

PulseLengthStatAnalyzerSettings::~PulseLengthStatAnalyzerSettings()
{
}

bool PulseLengthStatAnalyzerSettings::SetSettingsFromInterfaces()
{
	mInputChannel = mInputChannelInterface.GetChannel();

	ClearChannels();
	AddChannel(mInputChannel, "Pulse Length Stat", true);

	return true;
}

void PulseLengthStatAnalyzerSettings::UpdateInterfacesFromSettings()
{
	mInputChannelInterface.SetChannel(mInputChannel);
}

void PulseLengthStatAnalyzerSettings::LoadSettings(const char* settings)
{
	SimpleArchive text_archive;
	text_archive.SetString(settings);

	text_archive >> mInputChannel;

	ClearChannels();
	AddChannel(mInputChannel, "Pulse Length Stat", true);

	UpdateInterfacesFromSettings();
}

const char* PulseLengthStatAnalyzerSettings::SaveSettings()
{
	SimpleArchive text_archive;

	text_archive << mInputChannel;

	return SetReturnString(text_archive.GetString());
}
