// Created with MonoDevelop
//
//    QuickStep: Acquire, view and identify spectra 
//    Copyright (C) Hiperscan GmbH Dresden, Germany
//
//    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 3 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, see <http://www.gnu.org/licenses/>.




using System;
using System.IO;
using Hiperscan.ApoIdentCore;
using Hiperscan.ApoIdentCore.GuiControl;
using Hiperscan.GtkExtensions.StandardDialogs;
using Hiperscan.Unix;
using Microsoft.Win32;

namespace Hiperscan.Extensions.ApoIdent
{
    public class ImportantCustomerInfoDialog
    {   
        public static void Run(Gtk.Window parent, AppControl control)
        {
            var tmp = new ImportantCustomerInfoDialog(parent, control);
            if (tmp.HasInfo == false)
                return;

            UpdateArgs arg = new UpdateArgs();
            arg.DialogArgs.DontShowAgain = false;
            arg.DialogArgs.Title = Catalog.GetString("Important Advice");
            arg.DialogArgs.Message = tmp.Message;

            DontShowAgainInfoDialog.Run(parent, arg.DialogArgs);

            if (arg.DialogArgs.DontShowAgain == true)
                tmp.MarkAsRead();
        }

        private ImportantCustomerInfoDialog(Gtk.Window parent,  AppControl control)
        {
            this.Control = control;
            this.Parent = parent;
        }

        public void MarkAsRead()
        {
            try
            {
                if (FileIO.ExistsFile(this.MarkedFileName))
                    return;

                FileIO.CreateFile(this.MarkedFileName);
            }
            catch(Exception ex)
            {
                Console.WriteLine("Cannot mark important adivice as read: {0}", ex);
            }
        }


        //Change here the condition
        private bool Condition()
        {
            try
            {
                if (FileIO.ExistsFile(this.MarkedFileName))
                    return false;

                //Write here your own condition

                return true;
            }
            catch (Exception)
            {
                return true;
            }
        }

        public bool HasInfo
        {
            get
            {
                if (this.IsActive == false)
                    return false;

                if (this.Condition() == false)
                    return false;

                return true;
            }
        }

        private string MarkedFileName
        {
            get
            {
                return Path.Combine(this.Control.FileSystem.ConfigDir, this.InfoId); ;
            }
        }

        private AppControl Control { get; set; }
        private Gtk.Window Parent { get; set; }

        //set to true for the case that esists an important customer info
        private bool IsActive { get; set; } = false;

        //set a related id for an advice
        private string InfoId { get; set; } = "New_Features_2_5";

        //write here the advice text
        private string Message { get; } = Catalog.GetString(
@"<b>New Version 2.4</b>

Following new features are already preset. You can deactivate them again in the settings.

	-  ""Complementary tests / Identity tests"" as mandatory
	-  Output of parts of the validation document in the measuring protocol"
        );
    }
}
