// Code generated by Microsoft Kiota - DO NOT EDIT.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

package applications

import (
	"context"

	i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f "github.com/microsoft/kiota-abstractions-go"

	i1064077c0deed3e13037469d51458ffc82d2db75e239cd9605f39aaa91186035 "github.com/Azure/ARO-HCP/internal/graph/graphsdk/models"
	ib74729b4523c5f01686574660da4dcdaf5ad08b33986f91ff22cfcda6d06031e "github.com/Azure/ARO-HCP/internal/graph/graphsdk/models/odataerrors"
)

// ItemAddPasswordRequestBuilder provides operations to call the addPassword method.
type ItemAddPasswordRequestBuilder struct {
	i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.BaseRequestBuilder
}

// ItemAddPasswordRequestBuilderPostRequestConfiguration configuration for the request such as headers, query parameters, and middleware options.
type ItemAddPasswordRequestBuilderPostRequestConfiguration struct {
	// Request headers
	Headers *i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.RequestHeaders
	// Request options
	Options []i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.RequestOption
}

// NewItemAddPasswordRequestBuilderInternal instantiates a new ItemAddPasswordRequestBuilder and sets the default values.
func NewItemAddPasswordRequestBuilderInternal(pathParameters map[string]string, requestAdapter i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.RequestAdapter) *ItemAddPasswordRequestBuilder {
	m := &ItemAddPasswordRequestBuilder{
		BaseRequestBuilder: *i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.NewBaseRequestBuilder(requestAdapter, "{+baseurl}/applications/{application%2Did}/addPassword", pathParameters),
	}
	return m
}

// NewItemAddPasswordRequestBuilder instantiates a new ItemAddPasswordRequestBuilder and sets the default values.
func NewItemAddPasswordRequestBuilder(rawUrl string, requestAdapter i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.RequestAdapter) *ItemAddPasswordRequestBuilder {
	urlParams := make(map[string]string)
	urlParams["request-raw-url"] = rawUrl
	return NewItemAddPasswordRequestBuilderInternal(urlParams, requestAdapter)
}

// Post adds a strong password or secret to an application.
// returns a PasswordCredentialable when successful
// returns a ODataError error when the service returns a 4XX or 5XX status code
// [Find more info here]
//
// [Find more info here]: https://learn.microsoft.com/graph/api/application-addpassword?view=graph-rest-1.0
func (m *ItemAddPasswordRequestBuilder) Post(ctx context.Context, body ItemAddPasswordPostRequestBodyable, requestConfiguration *ItemAddPasswordRequestBuilderPostRequestConfiguration) (i1064077c0deed3e13037469d51458ffc82d2db75e239cd9605f39aaa91186035.PasswordCredentialable, error) {
	requestInfo, err := m.ToPostRequestInformation(ctx, body, requestConfiguration)
	if err != nil {
		return nil, err
	}
	errorMapping := i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.ErrorMappings{
		"XXX": ib74729b4523c5f01686574660da4dcdaf5ad08b33986f91ff22cfcda6d06031e.CreateODataErrorFromDiscriminatorValue,
	}
	res, err := m.BaseRequestBuilder.RequestAdapter.Send(ctx, requestInfo, i1064077c0deed3e13037469d51458ffc82d2db75e239cd9605f39aaa91186035.CreatePasswordCredentialFromDiscriminatorValue, errorMapping)
	if err != nil {
		return nil, err
	}
	if res == nil {
		return nil, nil
	}
	return res.(i1064077c0deed3e13037469d51458ffc82d2db75e239cd9605f39aaa91186035.PasswordCredentialable), nil
}

// ToPostRequestInformation adds a strong password or secret to an application.
// returns a *RequestInformation when successful
func (m *ItemAddPasswordRequestBuilder) ToPostRequestInformation(ctx context.Context, body ItemAddPasswordPostRequestBodyable, requestConfiguration *ItemAddPasswordRequestBuilderPostRequestConfiguration) (*i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.RequestInformation, error) {
	requestInfo := i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.NewRequestInformationWithMethodAndUrlTemplateAndPathParameters(i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.POST, m.BaseRequestBuilder.UrlTemplate, m.BaseRequestBuilder.PathParameters)
	if requestConfiguration != nil {
		requestInfo.Headers.AddAll(requestConfiguration.Headers)
		requestInfo.AddRequestOptions(requestConfiguration.Options)
	}
	requestInfo.Headers.TryAdd("Accept", "application/json")
	err := requestInfo.SetContentFromParsable(ctx, m.BaseRequestBuilder.RequestAdapter, "application/json", body)
	if err != nil {
		return nil, err
	}
	return requestInfo, nil
}

// WithUrl returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored.
// returns a *ItemAddPasswordRequestBuilder when successful
func (m *ItemAddPasswordRequestBuilder) WithUrl(rawUrl string) *ItemAddPasswordRequestBuilder {
	return NewItemAddPasswordRequestBuilder(rawUrl, m.BaseRequestBuilder.RequestAdapter)
}
