using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace barry
{
    public class BackupConfig
    {
        Methods methods = new Methods();

        // ID
        public string machine_guid;

        // target or source of the backup (it is a directory on the local computer) 
        private string _dir_path;
        public string dir_path
        {
            get
            {
                return _dir_path;
            }
            set
            {
                _dir_path = value;
            }
        }

        // (optional) a sub-diretory of the current device
        private string _local_subdir = "";
        public string local_subdir
        {
            get
            {
                return _local_subdir;
            }
            set
            {
                _local_subdir = value;
            }
        }

        public string local_subdir_path
        {
            get
            {
                return Path.Combine(methods.current_drive_letter(), _local_subdir);
            }
        }
        


        // operation type
        // 1 for a backup of the device on the computer (default)
        // 0 for nothing
        // -1 for a backup of the computer on the device
        public int bkp_type = 1;

        // last backup
        public string last_bkp_date = "Never";
        public string last_bkp_result = "";
        public string last_bkp_target = "";


        /// <summary>
        /// return an explicative text about what barry is going to do
        /// </summary>
        /// <returns></returns>
        public string describe()
        {
            
            string msg = "";
            if (bkp_type == 0)
            {
                msg = "Simple: Barry won't do nothing.";
            }
            else if (bkp_type == 1)
            {
                msg = String.Format("Barry will copy all of your files and directories:\nFrom your USB Device, in {0}\n To your computer, in {1}", methods.current_drive_letter() + local_subdir, dir_path);
            }
            else if (bkp_type == 1)
            {
                msg = String.Format("Barry will copy all of your files and directories:\nFrom your computer, in {1}\n To your USB Device, in {0}", methods.current_drive_letter() + local_subdir, dir_path);
            }
            else
            {
                msg = "Problem: Barry don't know what he should do. And he do not like it...";
            }

            msg += "\nThe last time Barry did that was " + last_bkp_date + ", and it was a " + last_bkp_result;
            return msg;
        }

        /// <summary>
        /// return an empty string if the current configration is valid
        /// a list of problems if not
        /// </summary>
        /// <returns></returns>
        public string checkup()
        {
            if (machine_guid != methods.get_machine_guid())
            {
                return "Checkup: Barry need to be on the good computer to check-up this config";
            }

            if (!Directory.Exists(dir_path))
            {
                return "This directory does not exists: " + dir_path;
            }
            else if (methods.is_subdir(dir_path, methods.current_drive_letter()))
            {
                //"This directory should NOT be on your usb device"
                //throw new ArgumentException();
                return "This directory should NOT be on your usb device: " + dir_path;
            }

            if (!Directory.Exists(local_subdir_path))
            {
                return "This directory does not exists: " + local_subdir_path;
            }
            else if (local_subdir.Length > 0 && !methods.is_subdir(local_subdir_path, methods.current_drive_letter()))
            {
                //"This directory should be on your usb device"
                return "This directory should be on your usb device: " + local_subdir_path;
            }
            return "";
        }


    }

}
