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

package com.azure.resourcemanager.workloads.models;

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

/**
 * A pre-created user assigned identity with appropriate roles assigned. To learn more on identity and roles required,
 * visit the ACSS how-to-guide.
 */
@Fluent
public final class UserAssignedServiceIdentity {
    /*
     * Type of manage identity
     */
    @JsonProperty(value = "type", required = true)
    private ManagedServiceIdentityType type;

    /*
     * User assigned identities dictionary
     */
    @JsonProperty(value = "userAssignedIdentities")
    @JsonInclude(value = JsonInclude.Include.NON_NULL, content = JsonInclude.Include.ALWAYS)
    private Map<String, UserAssignedIdentity> userAssignedIdentities;

    /** Creates an instance of UserAssignedServiceIdentity class. */
    public UserAssignedServiceIdentity() {
    }

    /**
     * Get the type property: Type of manage identity.
     *
     * @return the type value.
     */
    public ManagedServiceIdentityType type() {
        return this.type;
    }

    /**
     * Set the type property: Type of manage identity.
     *
     * @param type the type value to set.
     * @return the UserAssignedServiceIdentity object itself.
     */
    public UserAssignedServiceIdentity withType(ManagedServiceIdentityType type) {
        this.type = type;
        return this;
    }

    /**
     * Get the userAssignedIdentities property: User assigned identities dictionary.
     *
     * @return the userAssignedIdentities value.
     */
    public Map<String, UserAssignedIdentity> userAssignedIdentities() {
        return this.userAssignedIdentities;
    }

    /**
     * Set the userAssignedIdentities property: User assigned identities dictionary.
     *
     * @param userAssignedIdentities the userAssignedIdentities value to set.
     * @return the UserAssignedServiceIdentity object itself.
     */
    public UserAssignedServiceIdentity withUserAssignedIdentities(
        Map<String, UserAssignedIdentity> userAssignedIdentities) {
        this.userAssignedIdentities = userAssignedIdentities;
        return this;
    }

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

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