#include "CommittedLiveState.h"

bool CommittedLiveState::LoadPersistentStateValue(const JsonValue& root)
{
	return mLayerStack.LoadPersistentStateValue(root);
}

JsonValue CommittedLiveState::BuildPersistentStateValue(const ShaderPackageCatalog& shaderCatalog) const
{
	return mLayerStack.BuildPersistentStateValue(shaderCatalog);
}

void CommittedLiveState::NormalizeLayerIds()
{
	mLayerStack.NormalizeLayerIds();
}

void CommittedLiveState::EnsureDefaultsForAllLayers(const ShaderPackageCatalog& shaderCatalog)
{
	mLayerStack.EnsureDefaultsForAllLayers(shaderCatalog);
}

void CommittedLiveState::EnsureDefaultLayer(const ShaderPackageCatalog& shaderCatalog)
{
	mLayerStack.EnsureDefaultLayer(shaderCatalog);
}

void CommittedLiveState::RemoveLayersWithMissingPackages(const ShaderPackageCatalog& shaderCatalog)
{
	mLayerStack.RemoveLayersWithMissingPackages(shaderCatalog);
}

bool CommittedLiveState::CreateLayer(const ShaderPackageCatalog& shaderCatalog, const std::string& shaderId, std::string& error)
{
	return mLayerStack.CreateLayer(shaderCatalog, shaderId, error);
}

bool CommittedLiveState::DeleteLayer(const std::string& layerId, std::string& error)
{
	return mLayerStack.DeleteLayer(layerId, error);
}

bool CommittedLiveState::MoveLayer(const std::string& layerId, int direction, std::string& error)
{
	return mLayerStack.MoveLayer(layerId, direction, error);
}

bool CommittedLiveState::MoveLayerToIndex(const std::string& layerId, std::size_t targetIndex, std::string& error)
{
	return mLayerStack.MoveLayerToIndex(layerId, targetIndex, error);
}

bool CommittedLiveState::SetLayerBypassState(const std::string& layerId, bool bypassed, std::string& error)
{
	return mLayerStack.SetLayerBypassState(layerId, bypassed, error);
}

bool CommittedLiveState::SetLayerShaderSelection(const ShaderPackageCatalog& shaderCatalog, const std::string& layerId, const std::string& shaderId, std::string& error)
{
	return mLayerStack.SetLayerShaderSelection(shaderCatalog, layerId, shaderId, error);
}

bool CommittedLiveState::SetParameterValue(const std::string& layerId, const std::string& parameterId, const ShaderParameterValue& value, std::string& error)
{
	return mLayerStack.SetParameterValue(layerId, parameterId, value, error);
}

bool CommittedLiveState::ResetLayerParameterValues(const ShaderPackageCatalog& shaderCatalog, const std::string& layerId, std::string& error)
{
	return mLayerStack.ResetLayerParameterValues(shaderCatalog, layerId, error);
}

bool CommittedLiveState::HasLayer(const std::string& layerId) const
{
	return mLayerStack.HasLayer(layerId);
}

bool CommittedLiveState::TryGetParameterById(const ShaderPackageCatalog& shaderCatalog, const std::string& layerId, const std::string& parameterId, StoredParameterSnapshot& snapshot, std::string& error) const
{
	return mLayerStack.TryGetParameterById(shaderCatalog, layerId, parameterId, snapshot, error);
}

bool CommittedLiveState::TryGetParameterByControlKey(const ShaderPackageCatalog& shaderCatalog, const std::string& layerKey, const std::string& parameterKey, StoredParameterSnapshot& snapshot, std::string& error) const
{
	return mLayerStack.TryGetParameterByControlKey(shaderCatalog, layerKey, parameterKey, snapshot, error);
}

bool CommittedLiveState::ResolveLayerMove(const std::string& layerId, int direction, bool& shouldMove, std::string& error) const
{
	return mLayerStack.ResolveLayerMove(layerId, direction, shouldMove, error);
}

bool CommittedLiveState::ResolveLayerMoveToIndex(const std::string& layerId, std::size_t targetIndex, bool& shouldMove, std::string& error) const
{
	return mLayerStack.ResolveLayerMoveToIndex(layerId, targetIndex, shouldMove, error);
}

JsonValue CommittedLiveState::BuildStackPresetValue(const ShaderPackageCatalog& shaderCatalog, const std::string& presetName) const
{
	return mLayerStack.BuildStackPresetValue(shaderCatalog, presetName);
}

bool CommittedLiveState::LoadStackPresetValue(const ShaderPackageCatalog& shaderCatalog, const JsonValue& root, std::string& error)
{
	return mLayerStack.LoadStackPresetValue(shaderCatalog, root, error);
}

CommittedLiveStateReadModel CommittedLiveState::BuildReadModel(const ShaderPackageCatalog& shaderCatalog) const
{
	CommittedLiveStateReadModel model;
	model.layers = mLayerStack.Layers();
	model.packagesById = shaderCatalog.CaptureSnapshot().packagesById;
	return model;
}

std::vector<CommittedLiveState::LayerPersistentState> CommittedLiveState::CopyLayerStates() const
{
	return mLayerStack.Layers();
}

const std::vector<CommittedLiveState::LayerPersistentState>& CommittedLiveState::Layers() const
{
	return mLayerStack.Layers();
}

std::vector<CommittedLiveState::LayerPersistentState>& CommittedLiveState::Layers()
{
	return mLayerStack.Layers();
}

const CommittedLiveState::LayerPersistentState* CommittedLiveState::FindLayerById(const std::string& layerId) const
{
	return mLayerStack.FindLayerById(layerId);
}

const LayerStackStore& CommittedLiveState::LayerStack() const
{
	return mLayerStack;
}

LayerStackStore& CommittedLiveState::LayerStack()
{
	return mLayerStack;
}
