1package filesystems
2
3import (
4	"context"
5	"net/http"
6
7	"github.com/Azure/go-autorest/autorest"
8	"github.com/Azure/go-autorest/autorest/azure"
9	"github.com/Azure/go-autorest/autorest/validation"
10	"github.com/tombuildsstuff/giovanni/storage/internal/endpoints"
11)
12
13// Delete deletes a Data Lake Store Gen2 FileSystem within a Storage Account
14func (client Client) Delete(ctx context.Context, accountName string, fileSystemName string) (result autorest.Response, err error) {
15	if accountName == "" {
16		return result, validation.NewError("datalakestore.Client", "Delete", "`accountName` cannot be an empty string.")
17	}
18	if fileSystemName == "" {
19		return result, validation.NewError("datalakestore.Client", "Delete", "`fileSystemName` cannot be an empty string.")
20	}
21
22	req, err := client.DeletePreparer(ctx, accountName, fileSystemName)
23	if err != nil {
24		err = autorest.NewErrorWithError(err, "datalakestore.Client", "Delete", nil, "Failure preparing request")
25		return
26	}
27
28	resp, err := client.DeleteSender(req)
29	if err != nil {
30		result = autorest.Response{Response: resp}
31		err = autorest.NewErrorWithError(err, "datalakestore.Client", "Delete", resp, "Failure sending request")
32		return
33	}
34
35	result, err = client.DeleteResponder(resp)
36	if err != nil {
37		err = autorest.NewErrorWithError(err, "datalakestore.Client", "Delete", resp, "Failure responding to request")
38	}
39
40	return
41}
42
43// DeletePreparer prepares the Delete request.
44func (client Client) DeletePreparer(ctx context.Context, accountName string, fileSystemName string) (*http.Request, error) {
45	pathParameters := map[string]interface{}{
46		"fileSystemName": autorest.Encode("path", fileSystemName),
47	}
48
49	queryParameters := map[string]interface{}{
50		"resource": autorest.Encode("query", "filesystem"),
51	}
52
53	headers := map[string]interface{}{
54		"x-ms-version": APIVersion,
55	}
56
57	preparer := autorest.CreatePreparer(
58		autorest.AsDelete(),
59		autorest.WithBaseURL(endpoints.GetDataLakeStoreEndpoint(client.BaseURI, accountName)),
60		autorest.WithPathParameters("/{fileSystemName}", pathParameters),
61		autorest.WithQueryParameters(queryParameters),
62		autorest.WithHeaders(headers))
63
64	return preparer.Prepare((&http.Request{}).WithContext(ctx))
65}
66
67// DeleteSender sends the Delete request. The method will close the
68// http.Response Body if it receives an error.
69func (client Client) DeleteSender(req *http.Request) (*http.Response, error) {
70	return autorest.SendWithSender(client, req,
71		azure.DoRetryWithRegistration(client.Client))
72}
73
74// DeleteResponder handles the response to the Delete request. The method always
75// closes the http.Response Body.
76func (client Client) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
77	err = autorest.Respond(
78		resp,
79		client.ByInspecting(),
80		azure.WithErrorUnlessStatusCode(http.StatusAccepted),
81		autorest.ByClosing())
82	result = autorest.Response{Response: resp}
83
84	return
85}
86