//  
//   Rebex Sample Code License
// 
//   Copyright 2026, REBEX CR s.r.o.
//   All rights reserved.
//   https://www.rebex.net/
// 
//   Permission to use, copy, modify, and/or distribute this software for any
//   purpose with or without fee is hereby granted.
// 
//   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
//   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
//   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
//   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
//   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
//   OTHER DEALINGS IN THE SOFTWARE.
// 

using System;
using System.Collections.Generic;
using System.Text;

namespace Rebex.Samples
{
    /// <summary>
    /// Specifies operations to perform.
    /// </summary>
    public enum Operation { Encrypt, Decrypt }

    /// <summary>
    /// Command line arguments parser and storage.
    /// </summary>
    public class Arguments
    {
        private Operation _operation;
        private string _sourceFile;
        private string _destinationFile;
        private string _password;
        private bool _overwrite;

        // keyword for overwrite option
        private const string OverwriteOption = "overwrite";

        /// <summary>
        /// Gets the selected operation.
        /// </summary>
        public Operation Operation 
        {
            get { return _operation; }
            private set { _operation = value; }
        }

        /// <summary>
        /// Gets the source file path.
        /// </summary>
        public string SourceFile 
        {
            get { return _sourceFile; }
            private set { _sourceFile = value; }
        }

        /// <summary>
        /// Gets the destination path.
        /// </summary>
        public string DestinationFile 
        {
            get { return _destinationFile; }
            private set { _destinationFile = value; }
        }

        /// <summary>
        /// Gets the password to apply.
        /// </summary>
        public string Password 
        {
            get { return _password; }
            private set { _password = value; }
        }

        /// <summary>
        /// Gets a value indicating whether to overwrite existing file.
        /// </summary>
        public bool Overwrite 
        {
            get { return _overwrite; }
            private set { _overwrite = value; }
        }

        /// <summary>
        /// Creates the instance from command line arguments.
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        public Arguments(string[] args)
        {
            // check number of arguments
            if (args.Length < 4 || args.Length > 5)
            {
                throw new SampleException("Invalid number of arguments.");
            }

            // process arguments
            try
            {
                Operation = (Operation)Enum.Parse(typeof(Operation), args[0], true);
            }
            catch (ArgumentException)
            {
                throw new SampleException(string.Format("Unknown operation specified: {0}", args[0]));
            }			

            SourceFile = args[1];
            DestinationFile = args[2];
            Password = args[3];

            if (args.Length == 5)
            {
                if (args[4].Equals(OverwriteOption, StringComparison.OrdinalIgnoreCase))
                    Overwrite = true;
                else
                    throw new SampleException(string.Format("Unknown option specified: {0}", args[4]));
            }
        }
    }
}
