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

package cleanrooms

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

// Creates an intermediate table in a membership. An intermediate table stores a
// query definition that you can execute later using PopulateIntermediateTable to
// materialize cached results. The intermediate table is owned by the member with
// the CAN_QUERY ability. This operation does not execute the stored query.
func (c *Client) CreateIntermediateTable(ctx context.Context, params *CreateIntermediateTableInput, optFns ...func(*Options)) (*CreateIntermediateTableOutput, error) {
	if params == nil {
		params = &CreateIntermediateTableInput{}
	}

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

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

type CreateIntermediateTableInput struct {

	// The unique identifier of the membership where the intermediate table is created.
	//
	// This member is required.
	MembershipIdentifier *string

	// The display name for the intermediate table.
	//
	// This member is required.
	Name *string

	// The configuration that defines the analysis used to populate the intermediate
	// table. This configuration contains the SQL query or analysis template reference.
	//
	// This member is required.
	PopulationAnalysisConfiguration types.PopulationAnalysisConfiguration

	// A description of the intermediate table.
	Description *string

	// The Amazon Resource Name (ARN) of the customer-managed KMS key used to encrypt
	// the intermediate table data.
	KmsKeyArn *string

	// The number of days to retain populated data versions. Minimum value of 1,
	// maximum value of 365.
	RetentionInDays *int32

	// An optional label that you can assign to a resource when you create it. Each
	// tag consists of a key and an optional value, both of which you define. When you
	// use tagging, you can also use tag-based access control in IAM policies to
	// control access to this resource.
	Tags map[string]string

	noSmithyDocumentSerde
}

type CreateIntermediateTableOutput struct {

	// The intermediate table that was created.
	//
	// This member is required.
	IntermediateTable *types.IntermediateTable

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationCreateIntermediateTableMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestjson1_serializeOpCreateIntermediateTable{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpCreateIntermediateTable{}, 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, options); 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 = addOpCreateIntermediateTableValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "CreateIntermediateTable"), 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
}
