// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.automation.fluent.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.azure.resourcemanager.automation.models.FieldDefinition;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Map;

/** The properties of the create connection type. */
@Fluent
public final class ConnectionTypeCreateOrUpdateProperties {
    /*
     * Gets or sets a Boolean value to indicate if the connection type is global.
     */
    @JsonProperty(value = "isGlobal")
    private Boolean isGlobal;

    /*
     * Gets or sets the field definitions of the connection type.
     */
    @JsonProperty(value = "fieldDefinitions", required = true)
    @JsonInclude(value = JsonInclude.Include.NON_NULL, content = JsonInclude.Include.ALWAYS)
    private Map<String, FieldDefinition> fieldDefinitions;

    /**
     * Get the isGlobal property: Gets or sets a Boolean value to indicate if the connection type is global.
     *
     * @return the isGlobal value.
     */
    public Boolean isGlobal() {
        return this.isGlobal;
    }

    /**
     * Set the isGlobal property: Gets or sets a Boolean value to indicate if the connection type is global.
     *
     * @param isGlobal the isGlobal value to set.
     * @return the ConnectionTypeCreateOrUpdateProperties object itself.
     */
    public ConnectionTypeCreateOrUpdateProperties withIsGlobal(Boolean isGlobal) {
        this.isGlobal = isGlobal;
        return this;
    }

    /**
     * Get the fieldDefinitions property: Gets or sets the field definitions of the connection type.
     *
     * @return the fieldDefinitions value.
     */
    public Map<String, FieldDefinition> fieldDefinitions() {
        return this.fieldDefinitions;
    }

    /**
     * Set the fieldDefinitions property: Gets or sets the field definitions of the connection type.
     *
     * @param fieldDefinitions the fieldDefinitions value to set.
     * @return the ConnectionTypeCreateOrUpdateProperties object itself.
     */
    public ConnectionTypeCreateOrUpdateProperties withFieldDefinitions(Map<String, FieldDefinition> fieldDefinitions) {
        this.fieldDefinitions = fieldDefinitions;
        return this;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (fieldDefinitions() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        "Missing required property fieldDefinitions in model ConnectionTypeCreateOrUpdateProperties"));
        } else {
            fieldDefinitions()
                .values()
                .forEach(
                    e -> {
                        if (e != null) {
                            e.validate();
                        }
                    });
        }
    }

    private static final ClientLogger LOGGER = new ClientLogger(ConnectionTypeCreateOrUpdateProperties.class);
}
