using skyscraper5.UI.StreamAcquisition;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace skyscraper5.UI.StreamAcquirers
{
	[StreamAcquirer("File","Transport Stream File")]
	internal class FileStreamAcquirer : StreamAcquisition.AbstractStreamAcquirer<FileInfo>
	{
		public override FileInfo AskUserForHandle(IWin32Window parent)
		{
			OpenFileDialog openFileDialog = new OpenFileDialog();
			openFileDialog.Filter = "MPEG-2 Transport Stream (*.ts)|*.ts";
			openFileDialog.Multiselect = false;
			openFileDialog.CheckFileExists = true;
			openFileDialog.CheckPathExists = true;
			DialogResult dialogResult = openFileDialog.ShowDialog(parent);
			switch(dialogResult)
			{
				case DialogResult.OK:
					return new FileInfo(openFileDialog.FileName);
				case DialogResult.Cancel:
					return null;
				default:
					throw new NotImplementedException(dialogResult.ToString());
			}
		}

		public override FileInfo GetHandle(string arg)
		{
			if (File.Exists(arg))
			{
				return new FileInfo(arg);
			}
			return null;
		}

		public override StreamSource GetStream(FileInfo inputHandle)
		{
			return new StreamSourceIoStreamWrapper(inputHandle.OpenRead(), inputHandle.Name);
		}
	}
}
