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

package cloudtrail

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

//	Enables Lake query federation on the specified event data store. Federating an
//
// event data store lets you view the metadata associated with the event data store
// in the Glue [Data Catalog]and run SQL queries against your event data using Amazon Athena.
// The table metadata stored in the Glue Data Catalog lets the Athena query engine
// know how to find, read, and process the data that you want to query.
//
// When you enable Lake query federation, CloudTrail creates a managed database
// named aws:cloudtrail (if the database doesn't already exist) and a managed
// federated table in the Glue Data Catalog. The event data store ID is used for
// the table name. CloudTrail registers the role ARN and event data store in [Lake Formation], the
// service responsible for allowing fine-grained access control of the federated
// resources in the Glue Data Catalog.
//
// For more information about Lake query federation, see [Federate an event data store].
//
// [Federate an event data store]: https://docs.aws.amazon.com/awscloudtrail/latest/userguide/query-federation.html
// [Lake Formation]: https://docs.aws.amazon.com/awscloudtrail/latest/userguide/query-federation-lake-formation.html
// [Data Catalog]: https://docs.aws.amazon.com/glue/latest/dg/components-overview.html#data-catalog-intro
func (c *Client) EnableFederation(ctx context.Context, params *EnableFederationInput, optFns ...func(*Options)) (*EnableFederationOutput, error) {
	if params == nil {
		params = &EnableFederationInput{}
	}

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

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

type EnableFederationInput struct {

	// The ARN (or ID suffix of the ARN) of the event data store for which you want to
	// enable Lake query federation.
	//
	// This member is required.
	EventDataStore *string

	//  The ARN of the federation role to use for the event data store. Amazon Web
	// Services services like Lake Formation use this federation role to access data
	// for the federated event data store. The federation role must exist in your
	// account and provide the [required minimum permissions].
	//
	// [required minimum permissions]: https://docs.aws.amazon.com/awscloudtrail/latest/userguide/query-federation.html#query-federation-permissions-role
	//
	// This member is required.
	FederationRoleArn *string

	noSmithyDocumentSerde
}

type EnableFederationOutput struct {

	//  The ARN of the event data store for which you enabled Lake query federation.
	EventDataStoreArn *string

	//  The ARN of the federation role.
	FederationRoleArn *string

	//  The federation status.
	FederationStatus types.FederationStatus

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

	noSmithyDocumentSerde
}

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