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

// SharedGalleryInvitesClient contains the methods for the SharedGalleryInvites group.
// Don't use this type directly, use NewSharedGalleryInvitesClient() instead.
//
// Generated from API version 2025-12-03
type SharedGalleryInvitesClient struct {
	internal       *arm.Client
	subscriptionID string
}

// NewSharedGalleryInvitesClient creates a new instance of SharedGalleryInvitesClient 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 - Contains optional client configuration. Pass nil to accept the default values.
func NewSharedGalleryInvitesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*SharedGalleryInvitesClient, error) {
	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
	if err != nil {
		return nil, err
	}
	client := &SharedGalleryInvitesClient{
		subscriptionID: subscriptionID,
		internal:       cl,
	}
	return client, nil
}

// BeginGallerySharingAccept - Accept sharing of a subscription-level shared gallery.
// If the operation fails it returns an *azcore.ResponseError type.
//   - location - The name of the Azure region.
//   - sharedGallerySubscriptionID - The name of the SharedGallerySubscription
//   - sharedGalleryName - The name of the SharedGallerySubscription
//   - options - SharedGalleryInvitesClientBeginGallerySharingAcceptOptions contains the optional parameters for the SharedGalleryInvitesClient.BeginGallerySharingAccept
//     method.
func (client *SharedGalleryInvitesClient) BeginGallerySharingAccept(ctx context.Context, location string, sharedGallerySubscriptionID string, sharedGalleryName string, options *SharedGalleryInvitesClientBeginGallerySharingAcceptOptions) (*runtime.Poller[SharedGalleryInvitesClientGallerySharingAcceptResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.gallerySharingAccept(ctx, location, sharedGallerySubscriptionID, sharedGalleryName, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SharedGalleryInvitesClientGallerySharingAcceptResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[SharedGalleryInvitesClientGallerySharingAcceptResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// GallerySharingAccept - Accept sharing of a subscription-level shared gallery.
// If the operation fails it returns an *azcore.ResponseError type.
func (client *SharedGalleryInvitesClient) gallerySharingAccept(ctx context.Context, location string, sharedGallerySubscriptionID string, sharedGalleryName string, options *SharedGalleryInvitesClientBeginGallerySharingAcceptOptions) (*http.Response, error) {
	var err error
	const operationName = "SharedGalleryInvitesClient.BeginGallerySharingAccept"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.gallerySharingAcceptCreateRequest(ctx, location, sharedGallerySubscriptionID, sharedGalleryName, 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
}

// gallerySharingAcceptCreateRequest creates the GallerySharingAccept request.
func (client *SharedGalleryInvitesClient) gallerySharingAcceptCreateRequest(ctx context.Context, location string, sharedGallerySubscriptionID string, sharedGalleryName string, _ *SharedGalleryInvitesClientBeginGallerySharingAcceptOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/sharedGallerySubscriptions/{sharedGallerySubscriptionId}/sharedGalleries/{sharedGalleryName}/accept"
	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 sharedGallerySubscriptionID == "" {
		return nil, errors.New("parameter sharedGallerySubscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{sharedGallerySubscriptionId}", url.PathEscape(sharedGallerySubscriptionID))
	if sharedGalleryName == "" {
		return nil, errors.New("parameter sharedGalleryName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{sharedGalleryName}", url.PathEscape(sharedGalleryName))
	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", version20251203)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	return req, nil
}

// BeginGallerySharingReject - Reject sharing of a subscription-level shared gallery.
// If the operation fails it returns an *azcore.ResponseError type.
//   - location - The name of the Azure region.
//   - sharedGallerySubscriptionID - The name of the SharedGallerySubscription
//   - sharedGalleryName - The name of the SharedGallerySubscription
//   - options - SharedGalleryInvitesClientBeginGallerySharingRejectOptions contains the optional parameters for the SharedGalleryInvitesClient.BeginGallerySharingReject
//     method.
func (client *SharedGalleryInvitesClient) BeginGallerySharingReject(ctx context.Context, location string, sharedGallerySubscriptionID string, sharedGalleryName string, options *SharedGalleryInvitesClientBeginGallerySharingRejectOptions) (*runtime.Poller[SharedGalleryInvitesClientGallerySharingRejectResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.gallerySharingReject(ctx, location, sharedGallerySubscriptionID, sharedGalleryName, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SharedGalleryInvitesClientGallerySharingRejectResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[SharedGalleryInvitesClientGallerySharingRejectResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// GallerySharingReject - Reject sharing of a subscription-level shared gallery.
// If the operation fails it returns an *azcore.ResponseError type.
func (client *SharedGalleryInvitesClient) gallerySharingReject(ctx context.Context, location string, sharedGallerySubscriptionID string, sharedGalleryName string, options *SharedGalleryInvitesClientBeginGallerySharingRejectOptions) (*http.Response, error) {
	var err error
	const operationName = "SharedGalleryInvitesClient.BeginGallerySharingReject"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.gallerySharingRejectCreateRequest(ctx, location, sharedGallerySubscriptionID, sharedGalleryName, 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
}

// gallerySharingRejectCreateRequest creates the GallerySharingReject request.
func (client *SharedGalleryInvitesClient) gallerySharingRejectCreateRequest(ctx context.Context, location string, sharedGallerySubscriptionID string, sharedGalleryName string, _ *SharedGalleryInvitesClientBeginGallerySharingRejectOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/sharedGallerySubscriptions/{sharedGallerySubscriptionId}/sharedGalleries/{sharedGalleryName}/reject"
	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 sharedGallerySubscriptionID == "" {
		return nil, errors.New("parameter sharedGallerySubscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{sharedGallerySubscriptionId}", url.PathEscape(sharedGallerySubscriptionID))
	if sharedGalleryName == "" {
		return nil, errors.New("parameter sharedGalleryName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{sharedGalleryName}", url.PathEscape(sharedGalleryName))
	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", version20251203)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	return req, nil
}
