1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package iotsitewise
4
5import (
6	"context"
7	"fmt"
8	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
9	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
10	"github.com/aws/aws-sdk-go-v2/service/iotsitewise/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Deletes an asset model. This action can't be undone. You must delete all assets
16// created from an asset model before you can delete the model. Also, you can't
17// delete an asset model if a parent asset model exists that contains a property
18// formula expression that depends on the asset model that you want to delete. For
19// more information, see Deleting assets and models
20// (https://docs.aws.amazon.com/iot-sitewise/latest/userguide/delete-assets-and-models.html)
21// in the AWS IoT SiteWise User Guide.
22func (c *Client) DeleteAssetModel(ctx context.Context, params *DeleteAssetModelInput, optFns ...func(*Options)) (*DeleteAssetModelOutput, error) {
23	if params == nil {
24		params = &DeleteAssetModelInput{}
25	}
26
27	result, metadata, err := c.invokeOperation(ctx, "DeleteAssetModel", params, optFns, addOperationDeleteAssetModelMiddlewares)
28	if err != nil {
29		return nil, err
30	}
31
32	out := result.(*DeleteAssetModelOutput)
33	out.ResultMetadata = metadata
34	return out, nil
35}
36
37type DeleteAssetModelInput struct {
38
39	// The ID of the asset model to delete.
40	//
41	// This member is required.
42	AssetModelId *string
43
44	// A unique case-sensitive identifier that you can provide to ensure the
45	// idempotency of the request. Don't reuse this client token if a new idempotent
46	// request is required.
47	ClientToken *string
48}
49
50type DeleteAssetModelOutput struct {
51
52	// The status of the asset model, which contains a state (DELETING after
53	// successfully calling this operation) and any error message.
54	//
55	// This member is required.
56	AssetModelStatus *types.AssetModelStatus
57
58	// Metadata pertaining to the operation's result.
59	ResultMetadata middleware.Metadata
60}
61
62func addOperationDeleteAssetModelMiddlewares(stack *middleware.Stack, options Options) (err error) {
63	err = stack.Serialize.Add(&awsRestjson1_serializeOpDeleteAssetModel{}, middleware.After)
64	if err != nil {
65		return err
66	}
67	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpDeleteAssetModel{}, middleware.After)
68	if err != nil {
69		return err
70	}
71	if err = addSetLoggerMiddleware(stack, options); err != nil {
72		return err
73	}
74	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
75		return err
76	}
77	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
78		return err
79	}
80	if err = addResolveEndpointMiddleware(stack, options); err != nil {
81		return err
82	}
83	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
84		return err
85	}
86	if err = addRetryMiddlewares(stack, options); err != nil {
87		return err
88	}
89	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
90		return err
91	}
92	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
93		return err
94	}
95	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
96		return err
97	}
98	if err = addClientUserAgent(stack); err != nil {
99		return err
100	}
101	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
102		return err
103	}
104	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
105		return err
106	}
107	if err = addEndpointPrefix_opDeleteAssetModelMiddleware(stack); err != nil {
108		return err
109	}
110	if err = addIdempotencyToken_opDeleteAssetModelMiddleware(stack, options); err != nil {
111		return err
112	}
113	if err = addOpDeleteAssetModelValidationMiddleware(stack); err != nil {
114		return err
115	}
116	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDeleteAssetModel(options.Region), middleware.Before); err != nil {
117		return err
118	}
119	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
120		return err
121	}
122	if err = addResponseErrorMiddleware(stack); err != nil {
123		return err
124	}
125	if err = addRequestResponseLogging(stack, options); err != nil {
126		return err
127	}
128	return nil
129}
130
131type endpointPrefix_opDeleteAssetModelMiddleware struct {
132}
133
134func (*endpointPrefix_opDeleteAssetModelMiddleware) ID() string {
135	return "EndpointHostPrefix"
136}
137
138func (m *endpointPrefix_opDeleteAssetModelMiddleware) HandleSerialize(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) (
139	out middleware.SerializeOutput, metadata middleware.Metadata, err error,
140) {
141	if smithyhttp.GetHostnameImmutable(ctx) || smithyhttp.IsEndpointHostPrefixDisabled(ctx) {
142		return next.HandleSerialize(ctx, in)
143	}
144
145	req, ok := in.Request.(*smithyhttp.Request)
146	if !ok {
147		return out, metadata, fmt.Errorf("unknown transport type %T", in.Request)
148	}
149
150	req.URL.Host = "model." + req.URL.Host
151
152	return next.HandleSerialize(ctx, in)
153}
154func addEndpointPrefix_opDeleteAssetModelMiddleware(stack *middleware.Stack) error {
155	return stack.Serialize.Insert(&endpointPrefix_opDeleteAssetModelMiddleware{}, `OperationSerializer`, middleware.After)
156}
157
158type idempotencyToken_initializeOpDeleteAssetModel struct {
159	tokenProvider IdempotencyTokenProvider
160}
161
162func (*idempotencyToken_initializeOpDeleteAssetModel) ID() string {
163	return "OperationIdempotencyTokenAutoFill"
164}
165
166func (m *idempotencyToken_initializeOpDeleteAssetModel) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
167	out middleware.InitializeOutput, metadata middleware.Metadata, err error,
168) {
169	if m.tokenProvider == nil {
170		return next.HandleInitialize(ctx, in)
171	}
172
173	input, ok := in.Parameters.(*DeleteAssetModelInput)
174	if !ok {
175		return out, metadata, fmt.Errorf("expected middleware input to be of type *DeleteAssetModelInput ")
176	}
177
178	if input.ClientToken == nil {
179		t, err := m.tokenProvider.GetIdempotencyToken()
180		if err != nil {
181			return out, metadata, err
182		}
183		input.ClientToken = &t
184	}
185	return next.HandleInitialize(ctx, in)
186}
187func addIdempotencyToken_opDeleteAssetModelMiddleware(stack *middleware.Stack, cfg Options) error {
188	return stack.Initialize.Add(&idempotencyToken_initializeOpDeleteAssetModel{tokenProvider: cfg.IdempotencyTokenProvider}, middleware.Before)
189}
190
191func newServiceMetadataMiddleware_opDeleteAssetModel(region string) *awsmiddleware.RegisterServiceMetadata {
192	return &awsmiddleware.RegisterServiceMetadata{
193		Region:        region,
194		ServiceID:     ServiceID,
195		SigningName:   "iotsitewise",
196		OperationName: "DeleteAssetModel",
197	}
198}
199