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

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

// NewTenantLevelSharedGalleryInvitesClient creates a new instance of TenantLevelSharedGalleryInvitesClient with the specified values.
//   - credential - used to authorize requests. Usually a credential from azidentity.
//   - options - Contains optional client configuration. Pass nil to accept the default values.
func NewTenantLevelSharedGalleryInvitesClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*TenantLevelSharedGalleryInvitesClient, error) {
	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
	if err != nil {
		return nil, err
	}
	client := &TenantLevelSharedGalleryInvitesClient{
		internal: cl,
	}
	return client, nil
}

// BeginTenantLevelGallerySharingAccept - Accept sharing of a tenant-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 TenantLevelSharedGallerySubscription
//   - options - TenantLevelSharedGalleryInvitesClientBeginTenantLevelGallerySharingAcceptOptions contains the optional parameters
//     for the TenantLevelSharedGalleryInvitesClient.BeginTenantLevelGallerySharingAccept method.
func (client *TenantLevelSharedGalleryInvitesClient) BeginTenantLevelGallerySharingAccept(ctx context.Context, location string, sharedGallerySubscriptionID string, sharedGalleryName string, options *TenantLevelSharedGalleryInvitesClientBeginTenantLevelGallerySharingAcceptOptions) (*runtime.Poller[TenantLevelSharedGalleryInvitesClientTenantLevelGallerySharingAcceptResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.tenantLevelGallerySharingAccept(ctx, location, sharedGallerySubscriptionID, sharedGalleryName, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[TenantLevelSharedGalleryInvitesClientTenantLevelGallerySharingAcceptResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[TenantLevelSharedGalleryInvitesClientTenantLevelGallerySharingAcceptResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

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

// tenantLevelGallerySharingAcceptCreateRequest creates the TenantLevelGallerySharingAccept request.
func (client *TenantLevelSharedGalleryInvitesClient) tenantLevelGallerySharingAcceptCreateRequest(ctx context.Context, location string, sharedGallerySubscriptionID string, sharedGalleryName string, _ *TenantLevelSharedGalleryInvitesClientBeginTenantLevelGallerySharingAcceptOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Compute/locations/{location}/tenantLevelSharedGallerySubscriptions/{sharedGallerySubscriptionId}/sharedGalleries/{sharedGalleryName}/accept"
	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
}

// BeginTenantLevelGallerySharingReject - Reject sharing of a tenant-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 TenantLevelSharedGallerySubscription
//   - options - TenantLevelSharedGalleryInvitesClientBeginTenantLevelGallerySharingRejectOptions contains the optional parameters
//     for the TenantLevelSharedGalleryInvitesClient.BeginTenantLevelGallerySharingReject method.
func (client *TenantLevelSharedGalleryInvitesClient) BeginTenantLevelGallerySharingReject(ctx context.Context, location string, sharedGallerySubscriptionID string, sharedGalleryName string, options *TenantLevelSharedGalleryInvitesClientBeginTenantLevelGallerySharingRejectOptions) (*runtime.Poller[TenantLevelSharedGalleryInvitesClientTenantLevelGallerySharingRejectResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.tenantLevelGallerySharingReject(ctx, location, sharedGallerySubscriptionID, sharedGalleryName, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[TenantLevelSharedGalleryInvitesClientTenantLevelGallerySharingRejectResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[TenantLevelSharedGalleryInvitesClientTenantLevelGallerySharingRejectResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

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

// tenantLevelGallerySharingRejectCreateRequest creates the TenantLevelGallerySharingReject request.
func (client *TenantLevelSharedGalleryInvitesClient) tenantLevelGallerySharingRejectCreateRequest(ctx context.Context, location string, sharedGallerySubscriptionID string, sharedGalleryName string, _ *TenantLevelSharedGalleryInvitesClientBeginTenantLevelGallerySharingRejectOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Compute/locations/{location}/tenantLevelSharedGallerySubscriptions/{sharedGallerySubscriptionId}/sharedGalleries/{sharedGalleryName}/reject"
	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
}
