#pragma once

#include <windows.h>


namespace WAA = Windows::ApplicationModel::Activation;

namespace AStarDemoWin
{
	/// <summary>
	/// ContinuationManager is used to detect if the most recent activation was due
	/// to a continuation such as the FileOpenPicker or WebAuthenticationBroker
	/// </summary>
	ref class ContinuationManager sealed
	{
	private:
		WAA::IContinuationActivatedEventArgs^ args;
		bool handled;
		Platform::Guid id;

	public:
		void Continue(WAA::IContinuationActivatedEventArgs^ args);
		void Continue(WAA::IContinuationActivatedEventArgs^ args, Windows::UI::Xaml::Controls::Frame^ rootFrame);
		void MarkAsStale();
		WAA::IContinuationActivatedEventArgs^ GetContinuationArgs(bool includeStaleArgs);
		property Platform::Guid Id
		{
			Platform::Guid get()
			{
				return id;
			}
		}
		property WAA::IContinuationActivatedEventArgs^ ContinuationArgs
		{
			WAA::IContinuationActivatedEventArgs^ get()
			{
				if (handled)
					return nullptr;
				MarkAsStale();
				return args;
			}
		}
	};

	/// <summary>
	/// Implement this interface if your page invokes the file open picker
	/// API.
	/// </summary>
	public interface class IFileOpenPickerContinuable
	{
		/// <summary>
		/// This method is invoked when the file open picker returns picked
		/// files
		/// </summary>
		/// <param name="args">Activated event args object that contains returned files from file open picker</param>
		void ContinueFileOpenPicker(WAA::FileOpenPickerContinuationEventArgs^ args);
	};
}