// 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) Go Code Generator. DO NOT EDIT.

package armdependencymap

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"
)

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

// NewMapsClient creates a new instance of MapsClient 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 NewMapsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*MapsClient, error) {
	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
	if err != nil {
		return nil, err
	}
	client := &MapsClient{
		subscriptionID: subscriptionID,
		internal:       cl,
	}
	return client, nil
}

// BeginCreateOrUpdate - Create a MapsResource
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-01-31-preview
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - mapName - Maps resource name
//   - resource - Resource create parameters.
//   - options - MapsClientBeginCreateOrUpdateOptions contains the optional parameters for the MapsClient.BeginCreateOrUpdate
//     method.
func (client *MapsClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, mapName string, resource MapsResource, options *MapsClientBeginCreateOrUpdateOptions) (*runtime.Poller[MapsClientCreateOrUpdateResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.createOrUpdate(ctx, resourceGroupName, mapName, resource, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[MapsClientCreateOrUpdateResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[MapsClientCreateOrUpdateResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// CreateOrUpdate - Create a MapsResource
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-01-31-preview
func (client *MapsClient) createOrUpdate(ctx context.Context, resourceGroupName string, mapName string, resource MapsResource, options *MapsClientBeginCreateOrUpdateOptions) (*http.Response, error) {
	var err error
	const operationName = "MapsClient.BeginCreateOrUpdate"
	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, mapName, resource, options)
	if err != nil {
		return nil, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return nil, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) {
		err = runtime.NewResponseError(httpResp)
		return nil, err
	}
	return httpResp, nil
}

// createOrUpdateCreateRequest creates the CreateOrUpdate request.
func (client *MapsClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, mapName string, resource MapsResource, _ *MapsClientBeginCreateOrUpdateOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DependencyMap/maps/{mapName}"
	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 mapName == "" {
		return nil, errors.New("parameter mapName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{mapName}", url.PathEscape(mapName))
	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", "2025-01-31-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	req.Raw().Header["Content-Type"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, resource); err != nil {
		return nil, err
	}
	return req, nil
}

// BeginDelete - Delete a MapsResource
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-01-31-preview
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - mapName - Maps resource name
//   - options - MapsClientBeginDeleteOptions contains the optional parameters for the MapsClient.BeginDelete method.
func (client *MapsClient) BeginDelete(ctx context.Context, resourceGroupName string, mapName string, options *MapsClientBeginDeleteOptions) (*runtime.Poller[MapsClientDeleteResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.deleteOperation(ctx, resourceGroupName, mapName, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[MapsClientDeleteResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[MapsClientDeleteResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// Delete - Delete a MapsResource
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-01-31-preview
func (client *MapsClient) deleteOperation(ctx context.Context, resourceGroupName string, mapName string, options *MapsClientBeginDeleteOptions) (*http.Response, error) {
	var err error
	const operationName = "MapsClient.BeginDelete"
	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, mapName, options)
	if err != nil {
		return nil, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return nil, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNoContent) {
		err = runtime.NewResponseError(httpResp)
		return nil, err
	}
	return httpResp, nil
}

// deleteCreateRequest creates the Delete request.
func (client *MapsClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, mapName string, _ *MapsClientBeginDeleteOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DependencyMap/maps/{mapName}"
	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 mapName == "" {
		return nil, errors.New("parameter mapName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{mapName}", url.PathEscape(mapName))
	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", "2025-01-31-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// BeginExportDependencies - Export dependencies
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-01-31-preview
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - mapName - Maps resource name
//   - body - The content of the action request
//   - options - MapsClientBeginExportDependenciesOptions contains the optional parameters for the MapsClient.BeginExportDependencies
//     method.
func (client *MapsClient) BeginExportDependencies(ctx context.Context, resourceGroupName string, mapName string, body ExportDependenciesRequest, options *MapsClientBeginExportDependenciesOptions) (*runtime.Poller[MapsClientExportDependenciesResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.exportDependencies(ctx, resourceGroupName, mapName, body, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[MapsClientExportDependenciesResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[MapsClientExportDependenciesResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// ExportDependencies - Export dependencies
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-01-31-preview
func (client *MapsClient) exportDependencies(ctx context.Context, resourceGroupName string, mapName string, body ExportDependenciesRequest, options *MapsClientBeginExportDependenciesOptions) (*http.Response, error) {
	var err error
	const operationName = "MapsClient.BeginExportDependencies"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.exportDependenciesCreateRequest(ctx, resourceGroupName, mapName, body, options)
	if err != nil {
		return nil, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return nil, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusAccepted) {
		err = runtime.NewResponseError(httpResp)
		return nil, err
	}
	return httpResp, nil
}

// exportDependenciesCreateRequest creates the ExportDependencies request.
func (client *MapsClient) exportDependenciesCreateRequest(ctx context.Context, resourceGroupName string, mapName string, body ExportDependenciesRequest, _ *MapsClientBeginExportDependenciesOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DependencyMap/maps/{mapName}/exportDependencies"
	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 mapName == "" {
		return nil, errors.New("parameter mapName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{mapName}", url.PathEscape(mapName))
	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", "2025-01-31-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	req.Raw().Header["Content-Type"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, body); err != nil {
		return nil, err
	}
	return req, nil
}

// Get - Get a MapsResource
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-01-31-preview
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - mapName - Maps resource name
//   - options - MapsClientGetOptions contains the optional parameters for the MapsClient.Get method.
func (client *MapsClient) Get(ctx context.Context, resourceGroupName string, mapName string, options *MapsClientGetOptions) (MapsClientGetResponse, error) {
	var err error
	const operationName = "MapsClient.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, mapName, options)
	if err != nil {
		return MapsClientGetResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return MapsClientGetResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return MapsClientGetResponse{}, err
	}
	resp, err := client.getHandleResponse(httpResp)
	return resp, err
}

// getCreateRequest creates the Get request.
func (client *MapsClient) getCreateRequest(ctx context.Context, resourceGroupName string, mapName string, _ *MapsClientGetOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DependencyMap/maps/{mapName}"
	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 mapName == "" {
		return nil, errors.New("parameter mapName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{mapName}", url.PathEscape(mapName))
	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", "2025-01-31-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

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

// BeginGetConnectionsForProcessOnFocusedMachine - Get network connections of a process
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-01-31-preview
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - mapName - Maps resource name
//   - body - The content of the action request
//   - options - MapsClientBeginGetConnectionsForProcessOnFocusedMachineOptions contains the optional parameters for the MapsClient.BeginGetConnectionsForProcessOnFocusedMachine
//     method.
func (client *MapsClient) BeginGetConnectionsForProcessOnFocusedMachine(ctx context.Context, resourceGroupName string, mapName string, body GetConnectionsForProcessOnFocusedMachineRequest, options *MapsClientBeginGetConnectionsForProcessOnFocusedMachineOptions) (*runtime.Poller[MapsClientGetConnectionsForProcessOnFocusedMachineResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.getConnectionsForProcessOnFocusedMachine(ctx, resourceGroupName, mapName, body, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[MapsClientGetConnectionsForProcessOnFocusedMachineResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[MapsClientGetConnectionsForProcessOnFocusedMachineResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// GetConnectionsForProcessOnFocusedMachine - Get network connections of a process
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-01-31-preview
func (client *MapsClient) getConnectionsForProcessOnFocusedMachine(ctx context.Context, resourceGroupName string, mapName string, body GetConnectionsForProcessOnFocusedMachineRequest, options *MapsClientBeginGetConnectionsForProcessOnFocusedMachineOptions) (*http.Response, error) {
	var err error
	const operationName = "MapsClient.BeginGetConnectionsForProcessOnFocusedMachine"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.getConnectionsForProcessOnFocusedMachineCreateRequest(ctx, resourceGroupName, mapName, body, options)
	if err != nil {
		return nil, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return nil, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusAccepted) {
		err = runtime.NewResponseError(httpResp)
		return nil, err
	}
	return httpResp, nil
}

// getConnectionsForProcessOnFocusedMachineCreateRequest creates the GetConnectionsForProcessOnFocusedMachine request.
func (client *MapsClient) getConnectionsForProcessOnFocusedMachineCreateRequest(ctx context.Context, resourceGroupName string, mapName string, body GetConnectionsForProcessOnFocusedMachineRequest, _ *MapsClientBeginGetConnectionsForProcessOnFocusedMachineOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DependencyMap/maps/{mapName}/getConnectionsForProcessOnFocusedMachine"
	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 mapName == "" {
		return nil, errors.New("parameter mapName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{mapName}", url.PathEscape(mapName))
	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", "2025-01-31-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	req.Raw().Header["Content-Type"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, body); err != nil {
		return nil, err
	}
	return req, nil
}

// BeginGetConnectionsWithConnectedMachineForFocusedMachine - Get network connections between machines
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-01-31-preview
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - mapName - Maps resource name
//   - body - The content of the action request
//   - options - MapsClientBeginGetConnectionsWithConnectedMachineForFocusedMachineOptions contains the optional parameters for
//     the MapsClient.BeginGetConnectionsWithConnectedMachineForFocusedMachine method.
func (client *MapsClient) BeginGetConnectionsWithConnectedMachineForFocusedMachine(ctx context.Context, resourceGroupName string, mapName string, body GetConnectionsWithConnectedMachineForFocusedMachineRequest, options *MapsClientBeginGetConnectionsWithConnectedMachineForFocusedMachineOptions) (*runtime.Poller[MapsClientGetConnectionsWithConnectedMachineForFocusedMachineResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.getConnectionsWithConnectedMachineForFocusedMachine(ctx, resourceGroupName, mapName, body, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[MapsClientGetConnectionsWithConnectedMachineForFocusedMachineResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[MapsClientGetConnectionsWithConnectedMachineForFocusedMachineResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// GetConnectionsWithConnectedMachineForFocusedMachine - Get network connections between machines
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-01-31-preview
func (client *MapsClient) getConnectionsWithConnectedMachineForFocusedMachine(ctx context.Context, resourceGroupName string, mapName string, body GetConnectionsWithConnectedMachineForFocusedMachineRequest, options *MapsClientBeginGetConnectionsWithConnectedMachineForFocusedMachineOptions) (*http.Response, error) {
	var err error
	const operationName = "MapsClient.BeginGetConnectionsWithConnectedMachineForFocusedMachine"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.getConnectionsWithConnectedMachineForFocusedMachineCreateRequest(ctx, resourceGroupName, mapName, body, options)
	if err != nil {
		return nil, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return nil, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusAccepted) {
		err = runtime.NewResponseError(httpResp)
		return nil, err
	}
	return httpResp, nil
}

// getConnectionsWithConnectedMachineForFocusedMachineCreateRequest creates the GetConnectionsWithConnectedMachineForFocusedMachine request.
func (client *MapsClient) getConnectionsWithConnectedMachineForFocusedMachineCreateRequest(ctx context.Context, resourceGroupName string, mapName string, body GetConnectionsWithConnectedMachineForFocusedMachineRequest, _ *MapsClientBeginGetConnectionsWithConnectedMachineForFocusedMachineOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DependencyMap/maps/{mapName}/getConnectionsWithConnectedMachineForFocusedMachine"
	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 mapName == "" {
		return nil, errors.New("parameter mapName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{mapName}", url.PathEscape(mapName))
	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", "2025-01-31-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	req.Raw().Header["Content-Type"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, body); err != nil {
		return nil, err
	}
	return req, nil
}

// BeginGetDependencyViewForFocusedMachine - Get dependency map of single machine
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-01-31-preview
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - mapName - Maps resource name
//   - body - The content of the action request
//   - options - MapsClientBeginGetDependencyViewForFocusedMachineOptions contains the optional parameters for the MapsClient.BeginGetDependencyViewForFocusedMachine
//     method.
func (client *MapsClient) BeginGetDependencyViewForFocusedMachine(ctx context.Context, resourceGroupName string, mapName string, body GetDependencyViewForFocusedMachineRequest, options *MapsClientBeginGetDependencyViewForFocusedMachineOptions) (*runtime.Poller[MapsClientGetDependencyViewForFocusedMachineResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.getDependencyViewForFocusedMachine(ctx, resourceGroupName, mapName, body, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[MapsClientGetDependencyViewForFocusedMachineResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[MapsClientGetDependencyViewForFocusedMachineResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// GetDependencyViewForFocusedMachine - Get dependency map of single machine
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-01-31-preview
func (client *MapsClient) getDependencyViewForFocusedMachine(ctx context.Context, resourceGroupName string, mapName string, body GetDependencyViewForFocusedMachineRequest, options *MapsClientBeginGetDependencyViewForFocusedMachineOptions) (*http.Response, error) {
	var err error
	const operationName = "MapsClient.BeginGetDependencyViewForFocusedMachine"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.getDependencyViewForFocusedMachineCreateRequest(ctx, resourceGroupName, mapName, body, options)
	if err != nil {
		return nil, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return nil, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusAccepted) {
		err = runtime.NewResponseError(httpResp)
		return nil, err
	}
	return httpResp, nil
}

// getDependencyViewForFocusedMachineCreateRequest creates the GetDependencyViewForFocusedMachine request.
func (client *MapsClient) getDependencyViewForFocusedMachineCreateRequest(ctx context.Context, resourceGroupName string, mapName string, body GetDependencyViewForFocusedMachineRequest, _ *MapsClientBeginGetDependencyViewForFocusedMachineOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DependencyMap/maps/{mapName}/getDependencyViewForFocusedMachine"
	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 mapName == "" {
		return nil, errors.New("parameter mapName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{mapName}", url.PathEscape(mapName))
	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", "2025-01-31-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	req.Raw().Header["Content-Type"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, body); err != nil {
		return nil, err
	}
	return req, nil
}

// NewListByResourceGroupPager - List MapsResource resources by resource group
//
// Generated from API version 2025-01-31-preview
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - options - MapsClientListByResourceGroupOptions contains the optional parameters for the MapsClient.NewListByResourceGroupPager
//     method.
func (client *MapsClient) NewListByResourceGroupPager(resourceGroupName string, options *MapsClientListByResourceGroupOptions) *runtime.Pager[MapsClientListByResourceGroupResponse] {
	return runtime.NewPager(runtime.PagingHandler[MapsClientListByResourceGroupResponse]{
		More: func(page MapsClientListByResourceGroupResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *MapsClientListByResourceGroupResponse) (MapsClientListByResourceGroupResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "MapsClient.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 MapsClientListByResourceGroupResponse{}, err
			}
			return client.listByResourceGroupHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listByResourceGroupCreateRequest creates the ListByResourceGroup request.
func (client *MapsClient) listByResourceGroupCreateRequest(ctx context.Context, resourceGroupName string, _ *MapsClientListByResourceGroupOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DependencyMap/maps"
	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", "2025-01-31-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

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

// NewListBySubscriptionPager - List MapsResource resources by subscription ID
//
// Generated from API version 2025-01-31-preview
//   - options - MapsClientListBySubscriptionOptions contains the optional parameters for the MapsClient.NewListBySubscriptionPager
//     method.
func (client *MapsClient) NewListBySubscriptionPager(options *MapsClientListBySubscriptionOptions) *runtime.Pager[MapsClientListBySubscriptionResponse] {
	return runtime.NewPager(runtime.PagingHandler[MapsClientListBySubscriptionResponse]{
		More: func(page MapsClientListBySubscriptionResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *MapsClientListBySubscriptionResponse) (MapsClientListBySubscriptionResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "MapsClient.NewListBySubscriptionPager")
			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.listBySubscriptionCreateRequest(ctx, options)
			}, nil)
			if err != nil {
				return MapsClientListBySubscriptionResponse{}, err
			}
			return client.listBySubscriptionHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listBySubscriptionCreateRequest creates the ListBySubscription request.
func (client *MapsClient) listBySubscriptionCreateRequest(ctx context.Context, _ *MapsClientListBySubscriptionOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.DependencyMap/maps"
	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", "2025-01-31-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listBySubscriptionHandleResponse handles the ListBySubscription response.
func (client *MapsClient) listBySubscriptionHandleResponse(resp *http.Response) (MapsClientListBySubscriptionResponse, error) {
	result := MapsClientListBySubscriptionResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.MapsResourceListResult); err != nil {
		return MapsClientListBySubscriptionResponse{}, err
	}
	return result, nil
}

// BeginUpdate - Update a MapsResource
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-01-31-preview
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - mapName - Maps resource name
//   - properties - The resource properties to be updated.
//   - options - MapsClientBeginUpdateOptions contains the optional parameters for the MapsClient.BeginUpdate method.
func (client *MapsClient) BeginUpdate(ctx context.Context, resourceGroupName string, mapName string, properties MapsResourceTagsUpdate, options *MapsClientBeginUpdateOptions) (*runtime.Poller[MapsClientUpdateResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.update(ctx, resourceGroupName, mapName, properties, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[MapsClientUpdateResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[MapsClientUpdateResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// Update - Update a MapsResource
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-01-31-preview
func (client *MapsClient) update(ctx context.Context, resourceGroupName string, mapName string, properties MapsResourceTagsUpdate, options *MapsClientBeginUpdateOptions) (*http.Response, error) {
	var err error
	const operationName = "MapsClient.BeginUpdate"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.updateCreateRequest(ctx, resourceGroupName, mapName, properties, options)
	if err != nil {
		return nil, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return nil, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) {
		err = runtime.NewResponseError(httpResp)
		return nil, err
	}
	return httpResp, nil
}

// updateCreateRequest creates the Update request.
func (client *MapsClient) updateCreateRequest(ctx context.Context, resourceGroupName string, mapName string, properties MapsResourceTagsUpdate, _ *MapsClientBeginUpdateOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DependencyMap/maps/{mapName}"
	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 mapName == "" {
		return nil, errors.New("parameter mapName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{mapName}", url.PathEscape(mapName))
	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", "2025-01-31-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	req.Raw().Header["Content-Type"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, properties); err != nil {
		return nil, err
	}
	return req, nil
}
