﻿/*
 * SecureIO - Multi-platform I/O-management tool
 * Copyright(C) 2016-2017 Lukas Berger
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or(at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
using System.IO;

namespace SecureIO.Core.Tasks.Validator
{

	public abstract class AbstractImageValidatorTask : AbstractIOTask
	{

		public override string DisplayString
		{
			get => $"Validating {this.Destination}";
		}

		public override bool CanPause { get; } = false;

		public AbstractImageValidatorTask() { }

		protected override void PrepareTask()
		{
			base.PrepareTask();
			this.ProgressMax = 6;
		}

		protected override void RunStep(int step)
		{
			switch (step)
			{
				// preparing: destination
				case 1: DestinationFileOpen(FileAccess.Read); break;
				case 2: DestinationCreateStream(); break;

				// main task
				case 3:

					this.AddLogEntry("Starting validation of image...");
					this.IOMainTask();

					break;

				// finish
				case 4: ClosingSource(); break;
				case 5: ClosingDestination(); break;
				case 6: Cleanup(); break;
			}
		}

		protected override void IOMainTask()
		{
			if (ValidateImage())
				this.FinishStep($"Image successfully validated!");
			else
				this.FinishStep($"Failed to validate image...");
		}

		protected virtual bool ValidateImage() { return false; }

	}

}
