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

import (
	"context"
	"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"
	"strings"
)

// AttestationStatusesClient contains the methods for the AttestationStatuses group.
// Don't use this type directly, use NewAttestationStatusesClient() instead.
type AttestationStatusesClient struct {
	internal *arm.Client
}

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

// Get - Implements AttestationStatus GET method.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2025-06-01-preview
//   - resourceURI - The fully qualified Azure Resource manager identifier of the resource.
//   - options - AttestationStatusesClientGetOptions contains the optional parameters for the AttestationStatusesClient.Get method.
func (client *AttestationStatusesClient) Get(ctx context.Context, resourceURI string, options *AttestationStatusesClientGetOptions) (AttestationStatusesClientGetResponse, error) {
	var err error
	const operationName = "AttestationStatusesClient.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, resourceURI, options)
	if err != nil {
		return AttestationStatusesClientGetResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return AttestationStatusesClientGetResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return AttestationStatusesClientGetResponse{}, err
	}
	resp, err := client.getHandleResponse(httpResp)
	return resp, err
}

// getCreateRequest creates the Get request.
func (client *AttestationStatusesClient) getCreateRequest(ctx context.Context, resourceURI string, _ *AttestationStatusesClientGetOptions) (*policy.Request, error) {
	urlPath := "/{resourceUri}/providers/Microsoft.AzureStackHCI/virtualMachineInstances/default/attestationStatus/default"
	urlPath = strings.ReplaceAll(urlPath, "{resourceUri}", resourceURI)
	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", "2025-06-01-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

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