generated/api/Models/UpdateBackupDestination.json.cs

// Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.9.4, generator: @autorest/powershell@3.0.415)
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

namespace Commvault.Powershell.Models
{
    using static Commvault.Powershell.Runtime.Extensions;

    /// <summary>
    /// Region can be modified only when the backup destination does not belong to a region already
    /// </summary>
    public partial class UpdateBackupDestination
    {

        /// <summary>
        /// <c>AfterFromJson</c> will be called after the json deserialization has finished, allowing customization of the object
        /// before it is returned. Implement this method in a partial class to enable this behavior
        /// </summary>
        /// <param name="json">The JsonNode that should be deserialized into this object.</param>

        partial void AfterFromJson(Commvault.Powershell.Runtime.Json.JsonObject json);

        /// <summary>
        /// <c>AfterToJson</c> will be called after the json erialization has finished, allowing customization of the <see cref="Commvault.Powershell.Runtime.Json.JsonObject"
        /// /> before it is returned. Implement this method in a partial class to enable this behavior
        /// </summary>
        /// <param name="container">The JSON container that the serialization result will be placed in.</param>

        partial void AfterToJson(ref Commvault.Powershell.Runtime.Json.JsonObject container);

        /// <summary>
        /// <c>BeforeFromJson</c> will be called before the json deserialization has commenced, allowing complete customization of
        /// the object before it is deserialized.
        /// If you wish to disable the default deserialization entirely, return <c>true</c> in the <see "returnNow" /> output parameter.
        /// Implement this method in a partial class to enable this behavior.
        /// </summary>
        /// <param name="json">The JsonNode that should be deserialized into this object.</param>
        /// <param name="returnNow">Determines if the rest of the deserialization should be processed, or if the method should return
        /// instantly.</param>

        partial void BeforeFromJson(Commvault.Powershell.Runtime.Json.JsonObject json, ref bool returnNow);

        /// <summary>
        /// <c>BeforeToJson</c> will be called before the json serialization has commenced, allowing complete customization of the
        /// object before it is serialized.
        /// If you wish to disable the default serialization entirely, return <c>true</c> in the <see "returnNow" /> output parameter.
        /// Implement this method in a partial class to enable this behavior.
        /// </summary>
        /// <param name="container">The JSON container that the serialization result will be placed in.</param>
        /// <param name="returnNow">Determines if the rest of the serialization should be processed, or if the method should return
        /// instantly.</param>

        partial void BeforeToJson(ref Commvault.Powershell.Runtime.Json.JsonObject container, ref bool returnNow);

        /// <summary>
        /// Deserializes a <see cref="Commvault.Powershell.Runtime.Json.JsonNode"/> into an instance of Commvault.Powershell.Models.IUpdateBackupDestination.
        /// </summary>
        /// <param name="node">a <see cref="Commvault.Powershell.Runtime.Json.JsonNode" /> to deserialize from.</param>
        /// <returns>an instance of Commvault.Powershell.Models.IUpdateBackupDestination.</returns>
        public static Commvault.Powershell.Models.IUpdateBackupDestination FromJson(Commvault.Powershell.Runtime.Json.JsonNode node)
        {
            return node is Commvault.Powershell.Runtime.Json.JsonObject json ? new UpdateBackupDestination(json) : null;
        }

        /// <summary>
        /// Serializes this instance of <see cref="UpdateBackupDestination" /> into a <see cref="Commvault.Powershell.Runtime.Json.JsonNode" />.
        /// </summary>
        /// <param name="container">The <see cref="Commvault.Powershell.Runtime.Json.JsonObject"/> container to serialize this object into. If the caller
        /// passes in <c>null</c>, a new instance will be created and returned to the caller.</param>
        /// <param name="serializationMode">Allows the caller to choose the depth of the serialization. See <see cref="Commvault.Powershell.Runtime.SerializationMode"/>.</param>
        /// <returns>
        /// a serialized instance of <see cref="UpdateBackupDestination" /> as a <see cref="Commvault.Powershell.Runtime.Json.JsonNode" />.
        /// </returns>
        public Commvault.Powershell.Runtime.Json.JsonNode ToJson(Commvault.Powershell.Runtime.Json.JsonObject container, Commvault.Powershell.Runtime.SerializationMode serializationMode)
        {
            container = container ?? new Commvault.Powershell.Runtime.Json.JsonObject();

            bool returnNow = false;
            BeforeToJson(ref container, ref returnNow);
            if (returnNow)
            {
                return container;
            }
            AddIf( null != this._region ? (Commvault.Powershell.Runtime.Json.JsonNode) this._region.ToJson(null,serializationMode) : null, "region" ,container.Add );
            AddIf( null != this._sourceCopy ? (Commvault.Powershell.Runtime.Json.JsonNode) this._sourceCopy.ToJson(null,serializationMode) : null, "sourceCopy" ,container.Add );
            AddIf( null != this._extendedRetentionRules ? (Commvault.Powershell.Runtime.Json.JsonNode) this._extendedRetentionRules.ToJson(null,serializationMode) : null, "extendedRetentionRules" ,container.Add );
            AddIf( null != (((object)this._name)?.ToString()) ? (Commvault.Powershell.Runtime.Json.JsonNode) new Commvault.Powershell.Runtime.Json.JsonString(this._name.ToString()) : null, "name" ,container.Add );
            AddIf( null != (((object)this._backupsToCopy)?.ToString()) ? (Commvault.Powershell.Runtime.Json.JsonNode) new Commvault.Powershell.Runtime.Json.JsonString(this._backupsToCopy.ToString()) : null, "backupsToCopy" ,container.Add );
            AddIf( null != this._backupStartTime ? (Commvault.Powershell.Runtime.Json.JsonNode)new Commvault.Powershell.Runtime.Json.JsonNumber((long)this._backupStartTime) : null, "backupStartTime" ,container.Add );
            AddIf( null != this._enableDataAging ? (Commvault.Powershell.Runtime.Json.JsonNode)new Commvault.Powershell.Runtime.Json.JsonBoolean((bool)this._enableDataAging) : null, "enableDataAging" ,container.Add );
            AddIf( null != this._overrideRetentionSettings ? (Commvault.Powershell.Runtime.Json.JsonNode)new Commvault.Powershell.Runtime.Json.JsonBoolean((bool)this._overrideRetentionSettings) : null, "overrideRetentionSettings" ,container.Add );
            AddIf( null != (((object)this._retentionRuleType)?.ToString()) ? (Commvault.Powershell.Runtime.Json.JsonNode) new Commvault.Powershell.Runtime.Json.JsonString(this._retentionRuleType.ToString()) : null, "retentionRuleType" ,container.Add );
            AddIf( null != this._retentionPeriodDays ? (Commvault.Powershell.Runtime.Json.JsonNode)new Commvault.Powershell.Runtime.Json.JsonNumber((long)this._retentionPeriodDays) : null, "retentionPeriodDays" ,container.Add );
            AddIf( null != this._snapRecoveryPoints ? (Commvault.Powershell.Runtime.Json.JsonNode)new Commvault.Powershell.Runtime.Json.JsonNumber((long)this._snapRecoveryPoints) : null, "snapRecoveryPoints" ,container.Add );
            AddIf( null != this._useExtendedRetentionRules ? (Commvault.Powershell.Runtime.Json.JsonNode)new Commvault.Powershell.Runtime.Json.JsonBoolean((bool)this._useExtendedRetentionRules) : null, "useExtendedRetentionRules" ,container.Add );
            if (null != this._mappings)
            {
                var __w = new Commvault.Powershell.Runtime.Json.XNodeArray();
                foreach( var __x in this._mappings )
                {
                    AddIf(__x?.ToJson(null, serializationMode) ,__w.Add);
                }
                container.Add("mappings",__w);
            }
            AfterToJson(ref container);
            return container;
        }

        /// <summary>
        /// Deserializes a Commvault.Powershell.Runtime.Json.JsonObject into a new instance of <see cref="UpdateBackupDestination" />.
        /// </summary>
        /// <param name="json">A Commvault.Powershell.Runtime.Json.JsonObject instance to deserialize from.</param>
        internal UpdateBackupDestination(Commvault.Powershell.Runtime.Json.JsonObject json)
        {
            bool returnNow = false;
            BeforeFromJson(json, ref returnNow);
            if (returnNow)
            {
                return;
            }
            {_region = If( json?.PropertyT<Commvault.Powershell.Runtime.Json.JsonObject>("region"), out var __jsonRegion) ? Commvault.Powershell.Models.IdName.FromJson(__jsonRegion) : Region;}
            {_sourceCopy = If( json?.PropertyT<Commvault.Powershell.Runtime.Json.JsonObject>("sourceCopy"), out var __jsonSourceCopy) ? Commvault.Powershell.Models.IdName.FromJson(__jsonSourceCopy) : SourceCopy;}
            {_extendedRetentionRules = If( json?.PropertyT<Commvault.Powershell.Runtime.Json.JsonObject>("extendedRetentionRules"), out var __jsonExtendedRetentionRules) ? Commvault.Powershell.Models.ExtendedRetentionRules.FromJson(__jsonExtendedRetentionRules) : ExtendedRetentionRules;}
            {_name = If( json?.PropertyT<Commvault.Powershell.Runtime.Json.JsonString>("name"), out var __jsonName) ? (string)__jsonName : (string)Name;}
            {_backupsToCopy = If( json?.PropertyT<Commvault.Powershell.Runtime.Json.JsonString>("backupsToCopy"), out var __jsonBackupsToCopy) ? (string)__jsonBackupsToCopy : (string)BackupsToCopy;}
            {_backupStartTime = If( json?.PropertyT<Commvault.Powershell.Runtime.Json.JsonNumber>("backupStartTime"), out var __jsonBackupStartTime) ? (long?)__jsonBackupStartTime : BackupStartTime;}
            {_enableDataAging = If( json?.PropertyT<Commvault.Powershell.Runtime.Json.JsonBoolean>("enableDataAging"), out var __jsonEnableDataAging) ? (bool?)__jsonEnableDataAging : EnableDataAging;}
            {_overrideRetentionSettings = If( json?.PropertyT<Commvault.Powershell.Runtime.Json.JsonBoolean>("overrideRetentionSettings"), out var __jsonOverrideRetentionSettings) ? (bool?)__jsonOverrideRetentionSettings : OverrideRetentionSettings;}
            {_retentionRuleType = If( json?.PropertyT<Commvault.Powershell.Runtime.Json.JsonString>("retentionRuleType"), out var __jsonRetentionRuleType) ? (string)__jsonRetentionRuleType : (string)RetentionRuleType;}
            {_retentionPeriodDays = If( json?.PropertyT<Commvault.Powershell.Runtime.Json.JsonNumber>("retentionPeriodDays"), out var __jsonRetentionPeriodDays) ? (long?)__jsonRetentionPeriodDays : RetentionPeriodDays;}
            {_snapRecoveryPoints = If( json?.PropertyT<Commvault.Powershell.Runtime.Json.JsonNumber>("snapRecoveryPoints"), out var __jsonSnapRecoveryPoints) ? (long?)__jsonSnapRecoveryPoints : SnapRecoveryPoints;}
            {_useExtendedRetentionRules = If( json?.PropertyT<Commvault.Powershell.Runtime.Json.JsonBoolean>("useExtendedRetentionRules"), out var __jsonUseExtendedRetentionRules) ? (bool?)__jsonUseExtendedRetentionRules : UseExtendedRetentionRules;}
            {_mappings = If( json?.PropertyT<Commvault.Powershell.Runtime.Json.JsonArray>("mappings"), out var __jsonMappings) ? If( __jsonMappings as Commvault.Powershell.Runtime.Json.JsonArray, out var __v) ? new global::System.Func<Commvault.Powershell.Models.ISnapshotCopyMapping[]>(()=> global::System.Linq.Enumerable.ToArray(global::System.Linq.Enumerable.Select(__v, (__u)=>(Commvault.Powershell.Models.ISnapshotCopyMapping) (Commvault.Powershell.Models.SnapshotCopyMapping.FromJson(__u) )) ))() : null : Mappings;}
            AfterFromJson(json);
        }
    }
}