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

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

// PaloAltoNetworksCloudngfwOperationsClient contains the methods for the PaloAltoNetworksCloudngfwOperations group.
// Don't use this type directly, use NewPaloAltoNetworksCloudngfwOperationsClient() instead.
//
// Generated from API version 2025-10-08
type PaloAltoNetworksCloudngfwOperationsClient struct {
	internal       *arm.Client
	subscriptionID string
}

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

// CreateProductSerialNumber -
// If the operation fails it returns an *azcore.ResponseError type.
//   - options - PaloAltoNetworksCloudngfwOperationsClientCreateProductSerialNumberOptions contains the optional parameters for
//     the PaloAltoNetworksCloudngfwOperationsClient.CreateProductSerialNumber method.
func (client *PaloAltoNetworksCloudngfwOperationsClient) CreateProductSerialNumber(ctx context.Context, options *PaloAltoNetworksCloudngfwOperationsClientCreateProductSerialNumberOptions) (PaloAltoNetworksCloudngfwOperationsClientCreateProductSerialNumberResponse, error) {
	var err error
	const operationName = "PaloAltoNetworksCloudngfwOperationsClient.CreateProductSerialNumber"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.createProductSerialNumberCreateRequest(ctx, options)
	if err != nil {
		return PaloAltoNetworksCloudngfwOperationsClientCreateProductSerialNumberResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return PaloAltoNetworksCloudngfwOperationsClientCreateProductSerialNumberResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return PaloAltoNetworksCloudngfwOperationsClientCreateProductSerialNumberResponse{}, err
	}
	resp, err := client.createProductSerialNumberHandleResponse(httpResp)
	return resp, err
}

// createProductSerialNumberCreateRequest creates the CreateProductSerialNumber request.
func (client *PaloAltoNetworksCloudngfwOperationsClient) createProductSerialNumberCreateRequest(ctx context.Context, _ *PaloAltoNetworksCloudngfwOperationsClientCreateProductSerialNumberOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/providers/PaloAltoNetworks.Cloudngfw/createProductSerialNumber"
	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.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", version20251008)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// createProductSerialNumberHandleResponse handles the CreateProductSerialNumber response.
func (client *PaloAltoNetworksCloudngfwOperationsClient) createProductSerialNumberHandleResponse(resp *http.Response) (PaloAltoNetworksCloudngfwOperationsClientCreateProductSerialNumberResponse, error) {
	result := PaloAltoNetworksCloudngfwOperationsClientCreateProductSerialNumberResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.ProductSerialNumberRequestStatus); err != nil {
		return PaloAltoNetworksCloudngfwOperationsClientCreateProductSerialNumberResponse{}, err
	}
	return result, nil
}

// ListCloudManagerTenants -
// If the operation fails it returns an *azcore.ResponseError type.
//   - options - PaloAltoNetworksCloudngfwOperationsClientListCloudManagerTenantsOptions contains the optional parameters for
//     the PaloAltoNetworksCloudngfwOperationsClient.ListCloudManagerTenants method.
func (client *PaloAltoNetworksCloudngfwOperationsClient) ListCloudManagerTenants(ctx context.Context, options *PaloAltoNetworksCloudngfwOperationsClientListCloudManagerTenantsOptions) (PaloAltoNetworksCloudngfwOperationsClientListCloudManagerTenantsResponse, error) {
	var err error
	const operationName = "PaloAltoNetworksCloudngfwOperationsClient.ListCloudManagerTenants"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.listCloudManagerTenantsCreateRequest(ctx, options)
	if err != nil {
		return PaloAltoNetworksCloudngfwOperationsClientListCloudManagerTenantsResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return PaloAltoNetworksCloudngfwOperationsClientListCloudManagerTenantsResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return PaloAltoNetworksCloudngfwOperationsClientListCloudManagerTenantsResponse{}, err
	}
	resp, err := client.listCloudManagerTenantsHandleResponse(httpResp)
	return resp, err
}

// listCloudManagerTenantsCreateRequest creates the ListCloudManagerTenants request.
func (client *PaloAltoNetworksCloudngfwOperationsClient) listCloudManagerTenantsCreateRequest(ctx context.Context, _ *PaloAltoNetworksCloudngfwOperationsClientListCloudManagerTenantsOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/providers/PaloAltoNetworks.Cloudngfw/listCloudManagerTenants"
	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.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", version20251008)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listCloudManagerTenantsHandleResponse handles the ListCloudManagerTenants response.
func (client *PaloAltoNetworksCloudngfwOperationsClient) listCloudManagerTenantsHandleResponse(resp *http.Response) (PaloAltoNetworksCloudngfwOperationsClientListCloudManagerTenantsResponse, error) {
	result := PaloAltoNetworksCloudngfwOperationsClientListCloudManagerTenantsResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.CloudManagerTenantList); err != nil {
		return PaloAltoNetworksCloudngfwOperationsClientListCloudManagerTenantsResponse{}, err
	}
	return result, nil
}

// ListProductSerialNumberStatus -
// If the operation fails it returns an *azcore.ResponseError type.
//   - options - PaloAltoNetworksCloudngfwOperationsClientListProductSerialNumberStatusOptions contains the optional parameters
//     for the PaloAltoNetworksCloudngfwOperationsClient.ListProductSerialNumberStatus method.
func (client *PaloAltoNetworksCloudngfwOperationsClient) ListProductSerialNumberStatus(ctx context.Context, options *PaloAltoNetworksCloudngfwOperationsClientListProductSerialNumberStatusOptions) (PaloAltoNetworksCloudngfwOperationsClientListProductSerialNumberStatusResponse, error) {
	var err error
	const operationName = "PaloAltoNetworksCloudngfwOperationsClient.ListProductSerialNumberStatus"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.listProductSerialNumberStatusCreateRequest(ctx, options)
	if err != nil {
		return PaloAltoNetworksCloudngfwOperationsClientListProductSerialNumberStatusResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return PaloAltoNetworksCloudngfwOperationsClientListProductSerialNumberStatusResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNotFound) {
		err = runtime.NewResponseError(httpResp)
		return PaloAltoNetworksCloudngfwOperationsClientListProductSerialNumberStatusResponse{}, err
	}
	resp, err := client.listProductSerialNumberStatusHandleResponse(httpResp)
	return resp, err
}

// listProductSerialNumberStatusCreateRequest creates the ListProductSerialNumberStatus request.
func (client *PaloAltoNetworksCloudngfwOperationsClient) listProductSerialNumberStatusCreateRequest(ctx context.Context, _ *PaloAltoNetworksCloudngfwOperationsClientListProductSerialNumberStatusOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/providers/PaloAltoNetworks.Cloudngfw/listProductSerialNumberStatus"
	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.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", version20251008)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listProductSerialNumberStatusHandleResponse handles the ListProductSerialNumberStatus response.
func (client *PaloAltoNetworksCloudngfwOperationsClient) listProductSerialNumberStatusHandleResponse(resp *http.Response) (PaloAltoNetworksCloudngfwOperationsClientListProductSerialNumberStatusResponse, error) {
	result := PaloAltoNetworksCloudngfwOperationsClientListProductSerialNumberStatusResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.ProductSerialNumberStatus); err != nil {
		return PaloAltoNetworksCloudngfwOperationsClientListProductSerialNumberStatusResponse{}, err
	}
	return result, nil
}

// ListSupportInfo -
// If the operation fails it returns an *azcore.ResponseError type.
//   - options - PaloAltoNetworksCloudngfwOperationsClientListSupportInfoOptions contains the optional parameters for the PaloAltoNetworksCloudngfwOperationsClient.ListSupportInfo
//     method.
func (client *PaloAltoNetworksCloudngfwOperationsClient) ListSupportInfo(ctx context.Context, options *PaloAltoNetworksCloudngfwOperationsClientListSupportInfoOptions) (PaloAltoNetworksCloudngfwOperationsClientListSupportInfoResponse, error) {
	var err error
	const operationName = "PaloAltoNetworksCloudngfwOperationsClient.ListSupportInfo"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.listSupportInfoCreateRequest(ctx, options)
	if err != nil {
		return PaloAltoNetworksCloudngfwOperationsClientListSupportInfoResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return PaloAltoNetworksCloudngfwOperationsClientListSupportInfoResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return PaloAltoNetworksCloudngfwOperationsClientListSupportInfoResponse{}, err
	}
	resp, err := client.listSupportInfoHandleResponse(httpResp)
	return resp, err
}

// listSupportInfoCreateRequest creates the ListSupportInfo request.
func (client *PaloAltoNetworksCloudngfwOperationsClient) listSupportInfoCreateRequest(ctx context.Context, _ *PaloAltoNetworksCloudngfwOperationsClientListSupportInfoOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/providers/PaloAltoNetworks.Cloudngfw/listSupportInfo"
	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.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", version20251008)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listSupportInfoHandleResponse handles the ListSupportInfo response.
func (client *PaloAltoNetworksCloudngfwOperationsClient) listSupportInfoHandleResponse(resp *http.Response) (PaloAltoNetworksCloudngfwOperationsClientListSupportInfoResponse, error) {
	result := PaloAltoNetworksCloudngfwOperationsClientListSupportInfoResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.SupportInfoModel); err != nil {
		return PaloAltoNetworksCloudngfwOperationsClientListSupportInfoResponse{}, err
	}
	return result, nil
}
