//go:build go1.18
// +build go1.18

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

package armdevhub

import (
	"context"
	"errors"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
	"net/http"
	"net/url"
	"strings"
)

// IacProfilesClient contains the methods for the IacProfiles group.
// Don't use this type directly, use NewIacProfilesClient() instead.
type IacProfilesClient struct {
	internal       *arm.Client
	subscriptionID string
}

// NewIacProfilesClient creates a new instance of IacProfilesClient with the specified values.
//   - subscriptionID - The ID of the target subscription. The value must be an UUID.
//   - credential - used to authorize requests. Usually a credential from azidentity.
//   - options - pass nil to accept the default values.
func NewIacProfilesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*IacProfilesClient, error) {
	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
	if err != nil {
		return nil, err
	}
	client := &IacProfilesClient{
		subscriptionID: subscriptionID,
		internal:       cl,
	}
	return client, nil
}

// CreateOrUpdate - Creates or updates a IacProfile
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-05-01-preview
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - iacProfileName - The name of the IacProfile.
//   - options - IacProfilesClientCreateOrUpdateOptions contains the optional parameters for the IacProfilesClient.CreateOrUpdate
//     method.
func (client *IacProfilesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, iacProfileName string, parameters IacProfile, options *IacProfilesClientCreateOrUpdateOptions) (IacProfilesClientCreateOrUpdateResponse, error) {
	var err error
	const operationName = "IacProfilesClient.CreateOrUpdate"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, iacProfileName, parameters, options)
	if err != nil {
		return IacProfilesClientCreateOrUpdateResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return IacProfilesClientCreateOrUpdateResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) {
		err = runtime.NewResponseError(httpResp)
		return IacProfilesClientCreateOrUpdateResponse{}, err
	}
	resp, err := client.createOrUpdateHandleResponse(httpResp)
	return resp, err
}

// createOrUpdateCreateRequest creates the CreateOrUpdate request.
func (client *IacProfilesClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, iacProfileName string, parameters IacProfile, options *IacProfilesClientCreateOrUpdateOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevHub/iacProfiles/{iacProfileName}"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if iacProfileName == "" {
		return nil, errors.New("parameter iacProfileName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{iacProfileName}", url.PathEscape(iacProfileName))
	req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-05-01-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, parameters); err != nil {
		return nil, err
	}
	return req, nil
}

// createOrUpdateHandleResponse handles the CreateOrUpdate response.
func (client *IacProfilesClient) createOrUpdateHandleResponse(resp *http.Response) (IacProfilesClientCreateOrUpdateResponse, error) {
	result := IacProfilesClientCreateOrUpdateResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.IacProfile); err != nil {
		return IacProfilesClientCreateOrUpdateResponse{}, err
	}
	return result, nil
}

// Delete - Deletes a IacProfile
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-05-01-preview
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - iacProfileName - The name of the IacProfile.
//   - options - IacProfilesClientDeleteOptions contains the optional parameters for the IacProfilesClient.Delete method.
func (client *IacProfilesClient) Delete(ctx context.Context, resourceGroupName string, iacProfileName string, options *IacProfilesClientDeleteOptions) (IacProfilesClientDeleteResponse, error) {
	var err error
	const operationName = "IacProfilesClient.Delete"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.deleteCreateRequest(ctx, resourceGroupName, iacProfileName, options)
	if err != nil {
		return IacProfilesClientDeleteResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return IacProfilesClientDeleteResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) {
		err = runtime.NewResponseError(httpResp)
		return IacProfilesClientDeleteResponse{}, err
	}
	return IacProfilesClientDeleteResponse{}, nil
}

// deleteCreateRequest creates the Delete request.
func (client *IacProfilesClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, iacProfileName string, options *IacProfilesClientDeleteOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevHub/iacProfiles/{iacProfileName}"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if iacProfileName == "" {
		return nil, errors.New("parameter iacProfileName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{iacProfileName}", url.PathEscape(iacProfileName))
	req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-05-01-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// Export - Export a template
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-05-01-preview
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - iacProfileName - The name of the IacProfile.
//   - options - IacProfilesClientExportOptions contains the optional parameters for the IacProfilesClient.Export method.
func (client *IacProfilesClient) Export(ctx context.Context, resourceGroupName string, iacProfileName string, parameters ExportTemplateRequest, options *IacProfilesClientExportOptions) (IacProfilesClientExportResponse, error) {
	var err error
	const operationName = "IacProfilesClient.Export"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.exportCreateRequest(ctx, resourceGroupName, iacProfileName, parameters, options)
	if err != nil {
		return IacProfilesClientExportResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return IacProfilesClientExportResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return IacProfilesClientExportResponse{}, err
	}
	resp, err := client.exportHandleResponse(httpResp)
	return resp, err
}

// exportCreateRequest creates the Export request.
func (client *IacProfilesClient) exportCreateRequest(ctx context.Context, resourceGroupName string, iacProfileName string, parameters ExportTemplateRequest, options *IacProfilesClientExportOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevHub/iacProfiles/{iacProfileName}/export"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if iacProfileName == "" {
		return nil, errors.New("parameter iacProfileName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{iacProfileName}", url.PathEscape(iacProfileName))
	req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-05-01-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, parameters); err != nil {
		return nil, err
	}
	return req, nil
}

// exportHandleResponse handles the Export response.
func (client *IacProfilesClient) exportHandleResponse(resp *http.Response) (IacProfilesClientExportResponse, error) {
	result := IacProfilesClientExportResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.PrLinkResponse); err != nil {
		return IacProfilesClientExportResponse{}, err
	}
	return result, nil
}

// Get - Gets a IacProfile.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-05-01-preview
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - iacProfileName - The name of the IacProfile.
//   - options - IacProfilesClientGetOptions contains the optional parameters for the IacProfilesClient.Get method.
func (client *IacProfilesClient) Get(ctx context.Context, resourceGroupName string, iacProfileName string, options *IacProfilesClientGetOptions) (IacProfilesClientGetResponse, error) {
	var err error
	const operationName = "IacProfilesClient.Get"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.getCreateRequest(ctx, resourceGroupName, iacProfileName, options)
	if err != nil {
		return IacProfilesClientGetResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return IacProfilesClientGetResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return IacProfilesClientGetResponse{}, err
	}
	resp, err := client.getHandleResponse(httpResp)
	return resp, err
}

// getCreateRequest creates the Get request.
func (client *IacProfilesClient) getCreateRequest(ctx context.Context, resourceGroupName string, iacProfileName string, options *IacProfilesClientGetOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevHub/iacProfiles/{iacProfileName}"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if iacProfileName == "" {
		return nil, errors.New("parameter iacProfileName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{iacProfileName}", url.PathEscape(iacProfileName))
	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-05-01-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// getHandleResponse handles the Get response.
func (client *IacProfilesClient) getHandleResponse(resp *http.Response) (IacProfilesClientGetResponse, error) {
	result := IacProfilesClientGetResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.IacProfile); err != nil {
		return IacProfilesClientGetResponse{}, err
	}
	return result, nil
}

// NewListPager - Gets a list of IacProfiles associated with the specified subscription.
//
// Generated from API version 2024-05-01-preview
//   - options - IacProfilesClientListOptions contains the optional parameters for the IacProfilesClient.NewListPager method.
func (client *IacProfilesClient) NewListPager(options *IacProfilesClientListOptions) *runtime.Pager[IacProfilesClientListResponse] {
	return runtime.NewPager(runtime.PagingHandler[IacProfilesClientListResponse]{
		More: func(page IacProfilesClientListResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *IacProfilesClientListResponse) (IacProfilesClientListResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "IacProfilesClient.NewListPager")
			nextLink := ""
			if page != nil {
				nextLink = *page.NextLink
			}
			resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
				return client.listCreateRequest(ctx, options)
			}, nil)
			if err != nil {
				return IacProfilesClientListResponse{}, err
			}
			return client.listHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listCreateRequest creates the List request.
func (client *IacProfilesClient) listCreateRequest(ctx context.Context, options *IacProfilesClientListOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.DevHub/iacProfiles"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-05-01-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listHandleResponse handles the List response.
func (client *IacProfilesClient) listHandleResponse(resp *http.Response) (IacProfilesClientListResponse, error) {
	result := IacProfilesClientListResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.IacProfileListResult); err != nil {
		return IacProfilesClientListResponse{}, err
	}
	return result, nil
}

// NewListByResourceGroupPager - Gets a list of iacProfiles within a resource group.
//
// Generated from API version 2024-05-01-preview
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - options - IacProfilesClientListByResourceGroupOptions contains the optional parameters for the IacProfilesClient.NewListByResourceGroupPager
//     method.
func (client *IacProfilesClient) NewListByResourceGroupPager(resourceGroupName string, options *IacProfilesClientListByResourceGroupOptions) *runtime.Pager[IacProfilesClientListByResourceGroupResponse] {
	return runtime.NewPager(runtime.PagingHandler[IacProfilesClientListByResourceGroupResponse]{
		More: func(page IacProfilesClientListByResourceGroupResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *IacProfilesClientListByResourceGroupResponse) (IacProfilesClientListByResourceGroupResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "IacProfilesClient.NewListByResourceGroupPager")
			nextLink := ""
			if page != nil {
				nextLink = *page.NextLink
			}
			resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
				return client.listByResourceGroupCreateRequest(ctx, resourceGroupName, options)
			}, nil)
			if err != nil {
				return IacProfilesClientListByResourceGroupResponse{}, err
			}
			return client.listByResourceGroupHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listByResourceGroupCreateRequest creates the ListByResourceGroup request.
func (client *IacProfilesClient) listByResourceGroupCreateRequest(ctx context.Context, resourceGroupName string, options *IacProfilesClientListByResourceGroupOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevHub/iacProfiles"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-05-01-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listByResourceGroupHandleResponse handles the ListByResourceGroup response.
func (client *IacProfilesClient) listByResourceGroupHandleResponse(resp *http.Response) (IacProfilesClientListByResourceGroupResponse, error) {
	result := IacProfilesClientListByResourceGroupResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.IacProfileListResult); err != nil {
		return IacProfilesClientListByResourceGroupResponse{}, err
	}
	return result, nil
}

// Scale - Scale by template
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-05-01-preview
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - iacProfileName - The name of the IacProfile.
//   - options - IacProfilesClientScaleOptions contains the optional parameters for the IacProfilesClient.Scale method.
func (client *IacProfilesClient) Scale(ctx context.Context, resourceGroupName string, iacProfileName string, parameters ScaleTemplateRequest, options *IacProfilesClientScaleOptions) (IacProfilesClientScaleResponse, error) {
	var err error
	const operationName = "IacProfilesClient.Scale"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.scaleCreateRequest(ctx, resourceGroupName, iacProfileName, parameters, options)
	if err != nil {
		return IacProfilesClientScaleResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return IacProfilesClientScaleResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return IacProfilesClientScaleResponse{}, err
	}
	resp, err := client.scaleHandleResponse(httpResp)
	return resp, err
}

// scaleCreateRequest creates the Scale request.
func (client *IacProfilesClient) scaleCreateRequest(ctx context.Context, resourceGroupName string, iacProfileName string, parameters ScaleTemplateRequest, options *IacProfilesClientScaleOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevHub/iacProfiles/{iacProfileName}/scale"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if iacProfileName == "" {
		return nil, errors.New("parameter iacProfileName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{iacProfileName}", url.PathEscape(iacProfileName))
	req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-05-01-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, parameters); err != nil {
		return nil, err
	}
	return req, nil
}

// scaleHandleResponse handles the Scale response.
func (client *IacProfilesClient) scaleHandleResponse(resp *http.Response) (IacProfilesClientScaleResponse, error) {
	result := IacProfilesClientScaleResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.PrLinkResponse); err != nil {
		return IacProfilesClientScaleResponse{}, err
	}
	return result, nil
}

// Sync - Sync template
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-05-01-preview
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - iacProfileName - The name of the IacProfile.
//   - options - IacProfilesClientSyncOptions contains the optional parameters for the IacProfilesClient.Sync method.
func (client *IacProfilesClient) Sync(ctx context.Context, resourceGroupName string, iacProfileName string, options *IacProfilesClientSyncOptions) (IacProfilesClientSyncResponse, error) {
	var err error
	const operationName = "IacProfilesClient.Sync"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.syncCreateRequest(ctx, resourceGroupName, iacProfileName, options)
	if err != nil {
		return IacProfilesClientSyncResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return IacProfilesClientSyncResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return IacProfilesClientSyncResponse{}, err
	}
	return IacProfilesClientSyncResponse{}, nil
}

// syncCreateRequest creates the Sync request.
func (client *IacProfilesClient) syncCreateRequest(ctx context.Context, resourceGroupName string, iacProfileName string, options *IacProfilesClientSyncOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevHub/iacProfiles/{iacProfileName}/sync"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if iacProfileName == "" {
		return nil, errors.New("parameter iacProfileName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{iacProfileName}", url.PathEscape(iacProfileName))
	req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-05-01-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// UpdateTags - Updates tags on a IacProfile.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-05-01-preview
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - iacProfileName - The name of the IacProfile.
//   - parameters - Parameters supplied to the Update TagsObject Tags operation.
//   - options - IacProfilesClientUpdateTagsOptions contains the optional parameters for the IacProfilesClient.UpdateTags method.
func (client *IacProfilesClient) UpdateTags(ctx context.Context, resourceGroupName string, iacProfileName string, parameters TagsObject, options *IacProfilesClientUpdateTagsOptions) (IacProfilesClientUpdateTagsResponse, error) {
	var err error
	const operationName = "IacProfilesClient.UpdateTags"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, iacProfileName, parameters, options)
	if err != nil {
		return IacProfilesClientUpdateTagsResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return IacProfilesClientUpdateTagsResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return IacProfilesClientUpdateTagsResponse{}, err
	}
	resp, err := client.updateTagsHandleResponse(httpResp)
	return resp, err
}

// updateTagsCreateRequest creates the UpdateTags request.
func (client *IacProfilesClient) updateTagsCreateRequest(ctx context.Context, resourceGroupName string, iacProfileName string, parameters TagsObject, options *IacProfilesClientUpdateTagsOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevHub/iacProfiles/{iacProfileName}"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if iacProfileName == "" {
		return nil, errors.New("parameter iacProfileName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{iacProfileName}", url.PathEscape(iacProfileName))
	req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-05-01-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, parameters); err != nil {
		return nil, err
	}
	return req, nil
}

// updateTagsHandleResponse handles the UpdateTags response.
func (client *IacProfilesClient) updateTagsHandleResponse(resp *http.Response) (IacProfilesClientUpdateTagsResponse, error) {
	result := IacProfilesClientUpdateTagsResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.IacProfile); err != nil {
		return IacProfilesClientUpdateTagsResponse{}, err
	}
	return result, nil
}
