// Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.9, generator: @autorest/go@4.0.0-preview.74)
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
// Code generated by @autorest/go. DO NOT EDIT.

package armredhatopenshifthcp

import (
	"context"
	"errors"
	"net/http"
	"net/url"
	"strings"

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

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

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

// Get - Get a HcpOperatorIdentityRoleSet
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2026-06-30-preview
//   - location - The name of the Azure region.
//   - hcpOperatorIdentityRoleSetName - The OpenShift minor version these identities are required for.
//   - options - HcpOperatorIdentityRoleSetsClientGetOptions contains the optional parameters for the HcpOperatorIdentityRoleSetsClient.Get
//     method.
func (client *HcpOperatorIdentityRoleSetsClient) Get(ctx context.Context, location string, hcpOperatorIdentityRoleSetName string, options *HcpOperatorIdentityRoleSetsClientGetOptions) (HcpOperatorIdentityRoleSetsClientGetResponse, error) {
	var err error
	const operationName = "HcpOperatorIdentityRoleSetsClient.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, location, hcpOperatorIdentityRoleSetName, options)
	if err != nil {
		return HcpOperatorIdentityRoleSetsClientGetResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return HcpOperatorIdentityRoleSetsClientGetResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return HcpOperatorIdentityRoleSetsClientGetResponse{}, err
	}
	resp, err := client.getHandleResponse(httpResp)
	return resp, err
}

// getCreateRequest creates the Get request.
func (client *HcpOperatorIdentityRoleSetsClient) getCreateRequest(ctx context.Context, location string, hcpOperatorIdentityRoleSetName string, _ *HcpOperatorIdentityRoleSetsClientGetOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.RedHatOpenShift/locations/{location}/hcpOperatorIdentityRoleSets/{hcpOperatorIdentityRoleSetName}"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if location == "" {
		return nil, errors.New("parameter location cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{location}", url.PathEscape(location))
	if hcpOperatorIdentityRoleSetName == "" {
		return nil, errors.New("parameter hcpOperatorIdentityRoleSetName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{hcpOperatorIdentityRoleSetName}", url.PathEscape(hcpOperatorIdentityRoleSetName))
	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", "2026-06-30-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

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

// NewListPager - List HcpOperatorIdentityRoleSet resources by SubscriptionLocationResource
//
// Generated from API version 2026-06-30-preview
//   - location - The name of the Azure region.
//   - options - HcpOperatorIdentityRoleSetsClientListOptions contains the optional parameters for the HcpOperatorIdentityRoleSetsClient.NewListPager
//     method.
func (client *HcpOperatorIdentityRoleSetsClient) NewListPager(location string, options *HcpOperatorIdentityRoleSetsClientListOptions) *runtime.Pager[HcpOperatorIdentityRoleSetsClientListResponse] {
	return runtime.NewPager(runtime.PagingHandler[HcpOperatorIdentityRoleSetsClientListResponse]{
		More: func(page HcpOperatorIdentityRoleSetsClientListResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *HcpOperatorIdentityRoleSetsClientListResponse) (HcpOperatorIdentityRoleSetsClientListResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "HcpOperatorIdentityRoleSetsClient.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, location, options)
			}, nil)
			if err != nil {
				return HcpOperatorIdentityRoleSetsClientListResponse{}, err
			}
			return client.listHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listCreateRequest creates the List request.
func (client *HcpOperatorIdentityRoleSetsClient) listCreateRequest(ctx context.Context, location string, _ *HcpOperatorIdentityRoleSetsClientListOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.RedHatOpenShift/locations/{location}/hcpOperatorIdentityRoleSets"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if location == "" {
		return nil, errors.New("parameter location cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{location}", url.PathEscape(location))
	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", "2026-06-30-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

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