//-----------------------------------------------------------------------
// 
//     Copyright (c) Microsoft Corporation.
// 
//-----------------------------------------------------------------------
namespace Microsoft.Isam.Esent.Interop
{
    using System;
    using System.Diagnostics;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using System.Runtime.InteropServices;
    /// 
    /// Holds a collection of data about a specific backup event.
    /// 
    [SuppressMessage(
        "Microsoft.StyleCop.CSharp.NamingRules",
        "SA1300:ElementMustBeginWithUpperCaseLetter",
        Justification = "This should match the name of the unmanaged structure.")]
    [StructLayout(LayoutKind.Sequential)]
    [Serializable]
    public struct JET_BKINFO : IEquatable, INullableJetStruct
    {
        /// 
        /// Current log position. 
        /// 
        private JET_LGPOS logPosition;
        /// 
        /// Time the backup was made.
        /// 
        private JET_BKLOGTIME backupTime;
        /// 
        /// Low log generation when the backup was made.
        /// 
        private uint lowGeneration;
        /// 
        /// High log generation when the backup was made.
        /// 
        private uint highGeneration;
        /// 
        /// Gets the log position of the backup.
        /// 
        public JET_LGPOS lgposMark
        {
            [DebuggerStepThrough]
            get { return this.logPosition; }
            internal set { this.logPosition = value; }
        }
        /// 
        /// Gets the time of the backup.
        /// 
        public JET_BKLOGTIME bklogtimeMark
        {
            [DebuggerStepThrough]
            get { return this.backupTime; }
            internal set { this.backupTime = value; }
        }
        /// 
        /// Gets the low generation of the backup.
        /// 
        public int genLow
        {
            [DebuggerStepThrough]
            get { return (int)this.lowGeneration; }
            internal set { this.lowGeneration = checked((uint)value); }
        }
        /// 
        /// Gets or sets the high generation of the backup.
        /// 
        public int genHigh
        {
            [DebuggerStepThrough]
            get { return (int)this.highGeneration; }
            set { this.highGeneration = checked((uint)value); }
        }
        /// 
        /// Gets a value indicating whether this backup info is null.
        /// 
        public bool HasValue
        {
            get
            {
                return this.lgposMark.HasValue
                       && this.backupTime.HasValue
                       && 0 != this.lowGeneration
                       && 0 != this.highGeneration;
            }
        }
        /// 
        /// Determines whether two specified instances of JET_BKINFO
        /// are equal.
        /// 
        /// The first instance to compare.
        /// The second instance to compare.
        /// True if the two instances are equal.
        public static bool operator ==(JET_BKINFO lhs, JET_BKINFO rhs)
        {
            return lhs.Equals(rhs);
        }
        /// 
        /// Determines whether two specified instances of JET_BKINFO
        /// are not equal.
        /// 
        /// The first instance to compare.
        /// The second instance to compare.
        /// True if the two instances are not equal.
        public static bool operator !=(JET_BKINFO lhs, JET_BKINFO rhs)
        {
            return !(lhs == rhs);
        }
        /// 
        /// Generate a string representation of the structure.
        /// 
        /// The structure as a string.
        public override string ToString()
        {
            return string.Format(
                CultureInfo.InvariantCulture,
                "JET_BKINFO({0}-{1}:{2}:{3})",
                this.genLow,
                this.genHigh,
                this.lgposMark,
                this.bklogtimeMark);
        }
        /// 
        /// Returns a value indicating whether this instance is equal
        /// to another instance.
        /// 
        /// An object to compare with this instance.
        /// True if the two instances are equal.
        public override bool Equals(object obj)
        {
            if (obj == null || this.GetType() != obj.GetType())
            {
                return false;
            }
            return this.Equals((JET_BKINFO)obj);
        }
        /// 
        /// Returns the hash code for this instance.
        /// 
        /// The hash code for this instance.
        public override int GetHashCode()
        {
            return this.logPosition.GetHashCode()
                   ^ this.backupTime.GetHashCode()
                   ^ unchecked((int)this.lowGeneration << 16)
                   ^ unchecked((int)this.lowGeneration >> 16)
                   ^ unchecked((int)this.highGeneration);
        }
        /// 
        /// Returns a value indicating whether this instance is equal
        /// to another instance.
        /// 
        /// An instance to compare with this instance.
        /// True if the two instances are equal.
        public bool Equals(JET_BKINFO other)
        {
            return this.logPosition == other.logPosition
                   && this.backupTime == other.backupTime
                   && this.lowGeneration == other.lowGeneration
                   && this.highGeneration == other.highGeneration;
        }
    }
}