//go:build go1.18
// +build go1.18

// 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) AutoRest Code Generator. DO NOT EDIT.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

package armselfhelp

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

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

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

// DiscoverSolutions - Search for relevant Azure Diagnostics, Solutions and Troubleshooters using a natural language issue
// summary.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-03-01-preview
//   - options - DiscoverySolutionNLPClientDiscoverSolutionsOptions contains the optional parameters for the DiscoverySolutionNLPClient.DiscoverSolutions
//     method.
func (client *DiscoverySolutionNLPClient) DiscoverSolutions(ctx context.Context, options *DiscoverySolutionNLPClientDiscoverSolutionsOptions) (DiscoverySolutionNLPClientDiscoverSolutionsResponse, error) {
	var err error
	const operationName = "DiscoverySolutionNLPClient.DiscoverSolutions"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.discoverSolutionsCreateRequest(ctx, options)
	if err != nil {
		return DiscoverySolutionNLPClientDiscoverSolutionsResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return DiscoverySolutionNLPClientDiscoverSolutionsResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return DiscoverySolutionNLPClientDiscoverSolutionsResponse{}, err
	}
	resp, err := client.discoverSolutionsHandleResponse(httpResp)
	return resp, err
}

// discoverSolutionsCreateRequest creates the DiscoverSolutions request.
func (client *DiscoverySolutionNLPClient) discoverSolutionsCreateRequest(ctx context.Context, options *DiscoverySolutionNLPClientDiscoverSolutionsOptions) (*policy.Request, error) {
	urlPath := "/providers/Microsoft.Help/discoverSolutions"
	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", "2024-03-01-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	if options != nil && options.DiscoverSolutionRequest != nil {
		if err := runtime.MarshalAsJSON(req, *options.DiscoverSolutionRequest); err != nil {
			return nil, err
		}
		return req, nil
	}
	return req, nil
}

// discoverSolutionsHandleResponse handles the DiscoverSolutions response.
func (client *DiscoverySolutionNLPClient) discoverSolutionsHandleResponse(resp *http.Response) (DiscoverySolutionNLPClientDiscoverSolutionsResponse, error) {
	result := DiscoverySolutionNLPClientDiscoverSolutionsResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.DiscoveryNlpResponse); err != nil {
		return DiscoverySolutionNLPClientDiscoverSolutionsResponse{}, err
	}
	return result, nil
}

// DiscoverSolutionsBySubscription - Search for relevant Azure Diagnostics, Solutions and Troubleshooters using a natural
// language issue summary and subscription.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-03-01-preview
//   - subscriptionID - The Azure subscription ID.
//   - options - DiscoverySolutionNLPClientDiscoverSolutionsBySubscriptionOptions contains the optional parameters for the DiscoverySolutionNLPClient.DiscoverSolutionsBySubscription
//     method.
func (client *DiscoverySolutionNLPClient) DiscoverSolutionsBySubscription(ctx context.Context, subscriptionID string, options *DiscoverySolutionNLPClientDiscoverSolutionsBySubscriptionOptions) (DiscoverySolutionNLPClientDiscoverSolutionsBySubscriptionResponse, error) {
	var err error
	const operationName = "DiscoverySolutionNLPClient.DiscoverSolutionsBySubscription"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.discoverSolutionsBySubscriptionCreateRequest(ctx, subscriptionID, options)
	if err != nil {
		return DiscoverySolutionNLPClientDiscoverSolutionsBySubscriptionResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return DiscoverySolutionNLPClientDiscoverSolutionsBySubscriptionResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return DiscoverySolutionNLPClientDiscoverSolutionsBySubscriptionResponse{}, err
	}
	resp, err := client.discoverSolutionsBySubscriptionHandleResponse(httpResp)
	return resp, err
}

// discoverSolutionsBySubscriptionCreateRequest creates the DiscoverSolutionsBySubscription request.
func (client *DiscoverySolutionNLPClient) discoverSolutionsBySubscriptionCreateRequest(ctx context.Context, subscriptionID string, options *DiscoverySolutionNLPClientDiscoverSolutionsBySubscriptionOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Help/discoverSolutions"
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", 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", "2024-03-01-preview")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	if options != nil && options.DiscoverSolutionRequest != nil {
		if err := runtime.MarshalAsJSON(req, *options.DiscoverSolutionRequest); err != nil {
			return nil, err
		}
		return req, nil
	}
	return req, nil
}

// discoverSolutionsBySubscriptionHandleResponse handles the DiscoverSolutionsBySubscription response.
func (client *DiscoverySolutionNLPClient) discoverSolutionsBySubscriptionHandleResponse(resp *http.Response) (DiscoverySolutionNLPClientDiscoverSolutionsBySubscriptionResponse, error) {
	result := DiscoverySolutionNLPClientDiscoverSolutionsBySubscriptionResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.DiscoveryNlpResponse); err != nil {
		return DiscoverySolutionNLPClientDiscoverSolutionsBySubscriptionResponse{}, err
	}
	return result, nil
}
