/* Code generated by Azure.Iot.Operations.ProtocolCompilerLib v1.0.0.0; DO NOT EDIT. */

#nullable enable

using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Azure.Iot.Operations.Services.EdgeRegistry.Host.Generated.Common;

namespace Azure.Iot.Operations.Services.EdgeRegistry.Host.Generated
{
    /// <summary>
    /// Request payload for creating a generic xRegistry Resource entity along with its default Version.
    /// </summary>
    [System.CodeDom.Compiler.GeneratedCode("Azure.Iot.Operations.ProtocolCompilerLib", "1.0.0.0")]
    public partial class CreateResourceRequestPayload : IJsonOnDeserialized, IJsonOnSerializing
    {
        /// <summary>
        /// Group identifier. Uses the default if not specified.
        /// </summary>
        [JsonPropertyName("groupId")]
        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
        public string? GroupId { get; set; } = default;

        /// <summary>
        /// The attributes needed to create the Resource Meta (its `meta` sub-entity).
        /// </summary>
        [JsonPropertyName("meta")]
        [JsonIgnore(Condition = JsonIgnoreCondition.Never)]
        [JsonRequired]
        public ResourceMetaAttributes Meta { get; set; } = default!;

        /// <summary>
        /// The attributes of the Resource's default Version, which will be created along side this Resource.
        /// </summary>
        [JsonPropertyName("defaultVersion")]
        [JsonIgnore(Condition = JsonIgnoreCondition.Never)]
        [JsonRequired]
        public VersionAttributes DefaultVersion { get; set; } = default!;

        /// <summary>
        /// Version identifier for the Resource's default Version, which is created along with this Resource. If omitted, the server determines the versionId.
        /// </summary>
        [JsonPropertyName("defaultVersionId")]
        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
        public string? DefaultVersionId { get; set; } = default;

        /// <summary>
        /// Extension-specific attributes.
        /// </summary>
        [JsonPropertyName("extensions")]
        [JsonIgnore(Condition = JsonIgnoreCondition.Never)]
        [JsonRequired]
        public Dictionary<string, byte[]> Extensions { get; set; } = default!;

        void IJsonOnDeserialized.OnDeserialized()
        {
            if (Meta is null)
            {
                throw new ArgumentNullException("meta field cannot be null");
            }
            if (DefaultVersion is null)
            {
                throw new ArgumentNullException("defaultVersion field cannot be null");
            }
            if (Extensions is null)
            {
                throw new ArgumentNullException("extensions field cannot be null");
            }
        }

        void IJsonOnSerializing.OnSerializing()
        {
            if (Meta is null)
            {
                throw new ArgumentNullException("meta field cannot be null");
            }
            if (DefaultVersion is null)
            {
                throw new ArgumentNullException("defaultVersion field cannot be null");
            }
            if (Extensions is null)
            {
                throw new ArgumentNullException("extensions field cannot be null");
            }
        }
    }
}
