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

package com.azure.resourcemanager.managedapplications.models;

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

/** The managed application provider authorization. */
@Fluent
public final class ApplicationProviderAuthorization {
    /*
     * The provider's principal identifier. This is the identity that the provider will use to call ARM to manage the
     * managed application resources.
     */
    @JsonProperty(value = "principalId", required = true)
    private String principalId;

    /*
     * The provider's role definition identifier. This role will define all the permissions that the provider must have
     * on the managed application's container resource group. This role definition cannot have permission to delete the
     * resource group.
     */
    @JsonProperty(value = "roleDefinitionId", required = true)
    private String roleDefinitionId;

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

    /**
     * Get the principalId property: The provider's principal identifier. This is the identity that the provider will
     * use to call ARM to manage the managed application resources.
     *
     * @return the principalId value.
     */
    public String principalId() {
        return this.principalId;
    }

    /**
     * Set the principalId property: The provider's principal identifier. This is the identity that the provider will
     * use to call ARM to manage the managed application resources.
     *
     * @param principalId the principalId value to set.
     * @return the ApplicationProviderAuthorization object itself.
     */
    public ApplicationProviderAuthorization withPrincipalId(String principalId) {
        this.principalId = principalId;
        return this;
    }

    /**
     * Get the roleDefinitionId property: The provider's role definition identifier. This role will define all the
     * permissions that the provider must have on the managed application's container resource group. This role
     * definition cannot have permission to delete the resource group.
     *
     * @return the roleDefinitionId value.
     */
    public String roleDefinitionId() {
        return this.roleDefinitionId;
    }

    /**
     * Set the roleDefinitionId property: The provider's role definition identifier. This role will define all the
     * permissions that the provider must have on the managed application's container resource group. This role
     * definition cannot have permission to delete the resource group.
     *
     * @param roleDefinitionId the roleDefinitionId value to set.
     * @return the ApplicationProviderAuthorization object itself.
     */
    public ApplicationProviderAuthorization withRoleDefinitionId(String roleDefinitionId) {
        this.roleDefinitionId = roleDefinitionId;
        return this;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (principalId() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        "Missing required property principalId in model ApplicationProviderAuthorization"));
        }
        if (roleDefinitionId() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        "Missing required property roleDefinitionId in model ApplicationProviderAuthorization"));
        }
    }

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