using System;

/*
    Copyright (c) 2010 flixmonk. (http://DVDSwarm.codeplex.com)
    All Rights Reserved.
        
    Redistribution and use in source and binary forms, with or without modification,
    are permitted provided that the following conditions are met:
        
    * Redistributions of source code must retain the above copyright notice, this list
      of conditions and the following disclaimer.
        
    * Redistributions in binary form must reproduce the above copyright notice, this
    list of conditions and the following disclaimer in the documentation and/or other
    materials provided with the distribution. 
        
    * Neither the name of The Flixmonk nor the names of its contributors may be used to
    endorse or promote products derived from this software without specific prior written
    permission.
        
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
    EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
    SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
    OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
    TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
namespace DVDSwarm
{
    /// <summary>
    /// Configuration Info.
    /// </summary>
    sealed public class ConfigurationInfo
    {
        #region Fields

        private Int32 _audioDelay = 0;
        private bool _audioDynamicRangeCompression = true;
        private FicSprout.Bacicworx.Media.EncoderQualityOption _audioEncoderQualityOption =
            FicSprout.Bacicworx.Media.EncoderQualityOption.High;
        private AudioFormat _audioFormat = AudioFormat.Vorbis;
        private OutputContainerFormat _containerFormat = OutputContainerFormat.Matroska;
        private CropMode _crop = CropMode.Auto;
        private bool _downmixAudio = true;
        private string _dvdOutputPath = string.Empty;
        private bool _normalizeAudio = true;
        private bool _shutdownAfterRun = false;
        private bool _smallestFilesize = false;
        private bool _throttle = true;
        private Int32 _throttleSeconds = 120;
        private FicSprout.Bacicworx.Media.EncoderQualityOption _videoEncoderQualityOption =
            FicSprout.Bacicworx.Media.EncoderQualityOption.High;
        private bool _writeDvdChapterFiles = true;
        private FicSprout.Snapzworx.Video.X264.DecoderLevel _x264DecoderLevel =
            FicSprout.Snapzworx.Video.X264.DecoderLevel.Auto;
        private FicSprout.Snapzworx.Video.X264.EncoderEfficiency _x264EncoderEfficiency =
            FicSprout.Snapzworx.Video.X264.EncoderEfficiency.Medium;
        private FicSprout.Snapzworx.Video.X264.InputTuning _x264InputTuning =
            FicSprout.Snapzworx.Video.X264.InputTuning.Film;
        private FicSprout.Snapzworx.Video.X264.OutputProfile _x264OutputProfile =
            FicSprout.Snapzworx.Video.X264.OutputProfile.None;
   
        #endregion

        #region Properties

        /// <summary>
        /// Gets and sets the default delay in milliseconds added to all audio tracks in addition
        /// to their individual delay value.
        /// </summary>
        public Int32 AudioDelay
        {
            get
            {
                return _audioDelay;
            }
            set
            {
                _audioDelay = value;
            }
        }
        /// <summary>
        /// Gets and sets the default Dynamic Range Compression (DRC) value for new audio tracks.
        /// </summary>
        public bool AudioDynamicRangeCompression
        {
            get
            {
                return _audioDynamicRangeCompression;
            }
            set
            {
                _audioDynamicRangeCompression = value;
            }
        }
        /// <summary>
        /// Gets and sets the audio encoder quality option.
        /// </summary>
        public FicSprout.Bacicworx.Media.EncoderQualityOption AudioEncoderQualityOption
        {
            get
            {
                return _audioEncoderQualityOption;
            }
            set
            {
                _audioEncoderQualityOption = value;
            }
        }
        /// <summary>
        /// Gets and sets the default audio encoder output format.
        /// </summary>
        public AudioFormat AudioFormat
        {
            get
            {
                return _audioFormat;
            }
            set
            {
                _audioFormat = value;
            }
        }
        /// <summary>
        /// Gets and sets the output container format.
        /// </summary>
        public OutputContainerFormat ContainerFormat
        {
            get
            {
                return _containerFormat;
            }
            set
            {
                _containerFormat = value;
            }
        }
        /// <summary>
        /// Gets and sets the default crop mode for the JobDialog.
        /// </summary>
        public CropMode Crop
        {
            get
            {
                return _crop;
            }
            set
            {
                _crop = value;
            }
        }
        /// <summary>
        /// Gets and sets the default downmix value for new audio tracks.
        /// </summary>
        public bool DownmixAudio
        {
            get
            {
                return _downmixAudio;
            }
            set
            {
                _downmixAudio = value;
            }
        }
        /// <summary>
        /// Gets and sets the DVD output folder where the demuxed video and audio streams are stored.
        /// </summary>
        public string DvdOutputPath
        {
            get
            {
                return _dvdOutputPath;
            }
            set
            {
                _dvdOutputPath = value;
            }
        }
        /// <summary>
        /// Gets and sets the default normalization value for new audio tracks.
        /// </summary>
        public bool NormalizeAudio
        {
            get
            {
                return _normalizeAudio;
            }
            set
            {
                _normalizeAudio = value;
            }
        }
        /// <summary>
        /// Gets and sets a value indicating whether to shutdown the computer after all jobs have finished.
        /// </summary>
        public bool ShutdownAfterRun
        {
            get
            {
                return _shutdownAfterRun;
            }
            set
            {
                _shutdownAfterRun = value;
            }
        }
        /// <summary>
        /// Gets and sets a value indicating whether to reduce the filesize as much as possible.
        /// </summary>
        public bool SmallestFilesize
        {
            get
            {
                return _smallestFilesize;
            }
            set
            {
                _smallestFilesize = value;
            }
        }
        /// <summary>
        /// Gets and sets a value indicating whether to throttle between each job.
        /// </summary>
        public bool Throttle
        {
            get
            {
                return _throttle;
            }
            set
            {
                _throttle = value;
            }
        }
        /// <summary>
        /// Gets and sets the delay between each job in seconds.
        /// </summary>
        public Int32 ThrottleSeconds
        {
            get
            {
                return _throttleSeconds;
            }
            set
            {
                _throttleSeconds = value;
            }
        }
        /// <summary>
        /// Gets and sets the video encoder quality option.
        /// </summary>
        public FicSprout.Bacicworx.Media.EncoderQualityOption VideoEncoderQualityOption
        {
            get
            {
                return _videoEncoderQualityOption;
            }
            set
            {
                _videoEncoderQualityOption = value;
            }
        }
        /// <summary>
        /// Gets and sets a value indicating whether to write the DVD chapters files.
        /// </summary>
        public bool WriteDvdChapterFiles
        {
            get
            {
                return _writeDvdChapterFiles;
            }
            set
            {
                _writeDvdChapterFiles = value;
            }
        }
        /// <summary>
        /// Gets and sets the x264 decoder level.
        /// </summary>
        public FicSprout.Snapzworx.Video.X264.DecoderLevel X264DecoderLevel
        {
            get
            {
                return _x264DecoderLevel;
            }
            set
            {
                _x264DecoderLevel = value;
            }
        }
        /// <summary>
        /// Gets and sets the x264 encoder efficiency.
        /// </summary>
        public FicSprout.Snapzworx.Video.X264.EncoderEfficiency X264EncoderEfficiency
        {
            get
            {
                return _x264EncoderEfficiency;
            }
            set
            {
                _x264EncoderEfficiency = value;
            }
        }
        /// <summary>
        /// Gets and sets the x264 input tuning.
        /// </summary>
        public FicSprout.Snapzworx.Video.X264.InputTuning X264InputTuning
        {
            get
            {
                return _x264InputTuning;
            }
            set
            {
                _x264InputTuning = value;
            }
        }
        /// <summary>
        /// Gets and sets the x264 output profile.
        /// </summary>
        public FicSprout.Snapzworx.Video.X264.OutputProfile X264OutputProfile
        {
            get
            {
                return _x264OutputProfile;
            }
            set
            {
                _x264OutputProfile = value;
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Clears internal values.
        /// </summary>
        public void Clear()
        {
            _audioDelay = 0;
            _audioDynamicRangeCompression = true;
            _audioEncoderQualityOption = FicSprout.Bacicworx.Media.EncoderQualityOption.High;
            _audioFormat = AudioFormat.Vorbis;
            _containerFormat = OutputContainerFormat.Matroska;
            _crop = CropMode.Auto;
            _downmixAudio = true;
            _dvdOutputPath = string.Empty;
            _normalizeAudio = true;
            _shutdownAfterRun = false;
            _smallestFilesize = false;
            _throttle = true;
            _throttleSeconds = 120;
            _videoEncoderQualityOption = FicSprout.Bacicworx.Media.EncoderQualityOption.High;
            _writeDvdChapterFiles = true;
            _x264DecoderLevel = FicSprout.Snapzworx.Video.X264.DecoderLevel.Auto;
            _x264EncoderEfficiency = FicSprout.Snapzworx.Video.X264.EncoderEfficiency.Medium;
            _x264InputTuning = FicSprout.Snapzworx.Video.X264.InputTuning.Film;
            _x264OutputProfile = FicSprout.Snapzworx.Video.X264.OutputProfile.None;
       }

        /// <summary>
        /// Copies data from another instance to this instance.
        /// </summary>
        /// <param name="config">A ConfigurationInfo instance to copy values from.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when config is null.</exception>
        public void Copy(ConfigurationInfo config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            Clear();

            _audioDelay = config._audioDelay;
            _audioDynamicRangeCompression = config._audioDynamicRangeCompression;
            _audioEncoderQualityOption = config._audioEncoderQualityOption;
            _audioFormat = config._audioFormat;
            _containerFormat = config._containerFormat;
            _crop = config._crop;
            _downmixAudio = config._downmixAudio;
            _dvdOutputPath = config._dvdOutputPath;
            _normalizeAudio = config._normalizeAudio;
            _shutdownAfterRun = config._shutdownAfterRun;
            _smallestFilesize = config._smallestFilesize;
            _throttle = config._throttle;
            _throttleSeconds = config._throttleSeconds;
            _videoEncoderQualityOption = config._videoEncoderQualityOption;
            _writeDvdChapterFiles = config._writeDvdChapterFiles;
            _x264DecoderLevel = config._x264DecoderLevel;
            _x264EncoderEfficiency = config._x264EncoderEfficiency;
            _x264InputTuning = config._x264InputTuning;
            _x264OutputProfile = config._x264OutputProfile;
        }

        #endregion
    }
}
