// Code generated by smithy-go-codegen DO NOT EDIT.

package datazone

import (
	"context"
	"fmt"
	"github.com/aws/aws-sdk-go-v2/service/datazone/types"
	"github.com/aws/smithy-go/middleware"
	smithyhttp "github.com/aws/smithy-go/transport/http"
	"time"
)

// Creates a data asset filter.
//
// Asset filters provide a sophisticated way to create controlled views of data
// assets by selecting specific columns or applying row-level filters. This
// capability is crucial for organizations that need to share data while
// maintaining security and privacy controls. For example, your database might be
// filtered to show only non-PII fields to certain users, or sales data might be
// filtered by region for different regional teams. Asset filters enable
// fine-grained access control while maintaining a single source of truth.
//
// Prerequisites:
//
//   - A valid domain ( --domain-identifier ) must exist.
//
//   - A data asset ( --asset-identifier ) must already be created under that
//     domain.
//
//   - The asset must have the referenced columns available in its schema for
//     column-based filtering.
//
//   - You cannot specify both ( columnConfiguration , rowConfiguration )at the
//     same time.
func (c *Client) CreateAssetFilter(ctx context.Context, params *CreateAssetFilterInput, optFns ...func(*Options)) (*CreateAssetFilterOutput, error) {
	if params == nil {
		params = &CreateAssetFilterInput{}
	}

	result, metadata, err := c.invokeOperation(ctx, "CreateAssetFilter", params, optFns, c.addOperationCreateAssetFilterMiddlewares)
	if err != nil {
		return nil, err
	}

	out := result.(*CreateAssetFilterOutput)
	out.ResultMetadata = metadata
	return out, nil
}

type CreateAssetFilterInput struct {

	// The ID of the data asset.
	//
	// This member is required.
	AssetIdentifier *string

	// The configuration of the asset filter.
	//
	// This member is required.
	Configuration types.AssetFilterConfiguration

	// The ID of the domain in which you want to create an asset filter.
	//
	// This member is required.
	DomainIdentifier *string

	// The name of the asset filter.
	//
	// This member is required.
	Name *string

	// A unique, case-sensitive identifier that is provided to ensure the idempotency
	// of the request.
	ClientToken *string

	// The description of the asset filter.
	Description *string

	noSmithyDocumentSerde
}

type CreateAssetFilterOutput struct {

	// The ID of the asset.
	//
	// This member is required.
	AssetId *string

	// The configuration of the asset filter.
	//
	// This member is required.
	Configuration types.AssetFilterConfiguration

	// The ID of the domain where the asset filter is created.
	//
	// This member is required.
	DomainId *string

	// The ID of the asset filter.
	//
	// This member is required.
	Id *string

	// The name of the asset filter.
	//
	// This member is required.
	Name *string

	// The timestamp at which the asset filter was created.
	CreatedAt *time.Time

	// The description of the asset filter.
	Description *string

	// The column names in the asset filter.
	EffectiveColumnNames []string

	// The row filter in the asset filter.
	EffectiveRowFilter *string

	// The error message that is displayed if the asset filter is not created
	// successfully.
	ErrorMessage *string

	// The status of the asset filter.
	Status types.FilterStatus

	// Metadata pertaining to the operation's result.
	ResultMetadata middleware.Metadata

	noSmithyDocumentSerde
}

func (c *Client) addOperationCreateAssetFilterMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestjson1_serializeOpCreateAssetFilter{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpCreateAssetFilter{}, middleware.After)
	if err != nil {
		return err
	}

	if err = addlegacyEndpointContextSetter(stack, options); err != nil {
		return err
	}
	if err = addComputeContentLength(stack); err != nil {
		return err
	}
	if err = addResolveEndpointMiddleware(stack, options); err != nil {
		return err
	}
	if err = addComputePayloadSHA256(stack); err != nil {
		return err
	}
	if err = addRecordResponseTiming(stack); err != nil {
		return err
	}
	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
		return err
	}
	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
		return err
	}
	if err = addCredentialSource(stack, options); err != nil {
		return err
	}
	if err = addIdempotencyToken_opCreateAssetFilterMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpCreateAssetFilterValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "CreateAssetFilter"), middleware.Before); err != nil {
		return err
	}
	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
		return err
	}
	if err = addResponseErrorMiddleware(stack); err != nil {
		return err
	}
	if err = addRequestResponseLogging(stack, options); err != nil {
		return err
	}
	if err = addDisableHTTPSMiddleware(stack, options); err != nil {
		return err
	}
	if err = addInterceptors(stack, options); err != nil {
		return err
	}
	return nil
}

type idempotencyToken_initializeOpCreateAssetFilter struct {
	tokenProvider IdempotencyTokenProvider
}

func (*idempotencyToken_initializeOpCreateAssetFilter) ID() string {
	return "OperationIdempotencyTokenAutoFill"
}

func (m *idempotencyToken_initializeOpCreateAssetFilter) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
	out middleware.InitializeOutput, metadata middleware.Metadata, err error,
) {
	if m.tokenProvider == nil {
		return next.HandleInitialize(ctx, in)
	}

	input, ok := in.Parameters.(*CreateAssetFilterInput)
	if !ok {
		return out, metadata, fmt.Errorf("expected middleware input to be of type *CreateAssetFilterInput ")
	}

	if input.ClientToken == nil {
		t, err := m.tokenProvider.GetIdempotencyToken()
		if err != nil {
			return out, metadata, err
		}
		input.ClientToken = &t
	}
	return next.HandleInitialize(ctx, in)
}
func addIdempotencyToken_opCreateAssetFilterMiddleware(stack *middleware.Stack, cfg Options) error {
	return stack.Initialize.Add(&idempotencyToken_initializeOpCreateAssetFilter{tokenProvider: cfg.IdempotencyTokenProvider}, middleware.Before)
}
