// 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 armcompute

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

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

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

// NewListByArtifactNamePager - List soft-deleted resources of an artifact in the gallery, such as soft-deleted gallery image
// version of an image.
//
// Generated from API version 2024-03-03
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - galleryName - The name of the Shared Image Gallery.
//   - artifactType - The type of the artifact to be listed, such as gallery image version.
//   - artifactName - The artifact name to be listed. If artifact type is Images, then the artifact name should be the gallery
//     image name.
//   - options - SoftDeletedResourceClientListByArtifactNameOptions contains the optional parameters for the SoftDeletedResourceClient.NewListByArtifactNamePager
//     method.
func (client *SoftDeletedResourceClient) NewListByArtifactNamePager(resourceGroupName string, galleryName string, artifactType string, artifactName string, options *SoftDeletedResourceClientListByArtifactNameOptions) *runtime.Pager[SoftDeletedResourceClientListByArtifactNameResponse] {
	return runtime.NewPager(runtime.PagingHandler[SoftDeletedResourceClientListByArtifactNameResponse]{
		More: func(page SoftDeletedResourceClientListByArtifactNameResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *SoftDeletedResourceClientListByArtifactNameResponse) (SoftDeletedResourceClientListByArtifactNameResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SoftDeletedResourceClient.NewListByArtifactNamePager")
			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.listByArtifactNameCreateRequest(ctx, resourceGroupName, galleryName, artifactType, artifactName, options)
			}, nil)
			if err != nil {
				return SoftDeletedResourceClientListByArtifactNameResponse{}, err
			}
			return client.listByArtifactNameHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listByArtifactNameCreateRequest creates the ListByArtifactName request.
func (client *SoftDeletedResourceClient) listByArtifactNameCreateRequest(ctx context.Context, resourceGroupName string, galleryName string, artifactType string, artifactName string, _ *SoftDeletedResourceClientListByArtifactNameOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/softdeletedartifacttypes/{artifactType}/artifacts/{artifactName}/versions"
	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 galleryName == "" {
		return nil, errors.New("parameter galleryName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{galleryName}", url.PathEscape(galleryName))
	if artifactType == "" {
		return nil, errors.New("parameter artifactType cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{artifactType}", url.PathEscape(artifactType))
	if artifactName == "" {
		return nil, errors.New("parameter artifactName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{artifactName}", url.PathEscape(artifactName))
	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-03-03")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listByArtifactNameHandleResponse handles the ListByArtifactName response.
func (client *SoftDeletedResourceClient) listByArtifactNameHandleResponse(resp *http.Response) (SoftDeletedResourceClientListByArtifactNameResponse, error) {
	result := SoftDeletedResourceClientListByArtifactNameResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.GallerySoftDeletedResourceList); err != nil {
		return SoftDeletedResourceClientListByArtifactNameResponse{}, err
	}
	return result, nil
}
