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

package bedrockagentcorecontrol

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

// Creates a new registry record within the specified registry. A registry record
// represents an individual AI resource's metadata in the registry. This could be
// an MCP server (and associated tools), A2A agent, agent skill, or a custom
// resource with a custom schema.
//
// The record is processed asynchronously and returns HTTP 202 Accepted.
func (c *Client) CreateRegistryRecord(ctx context.Context, params *CreateRegistryRecordInput, optFns ...func(*Options)) (*CreateRegistryRecordOutput, error) {
	if params == nil {
		params = &CreateRegistryRecordInput{}
	}

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

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

type CreateRegistryRecordInput struct {

	// The descriptor type of the registry record.
	//
	//   - MCP - Model Context Protocol descriptor for MCP-compatible servers and tools.
	//
	//   - A2A - Agent-to-Agent protocol descriptor.
	//
	//   - CUSTOM - Custom descriptor type for resources such as APIs, Lambda
	//   functions, or servers not conforming to a standard protocol.
	//
	//   - AGENT_SKILLS - Agent skills descriptor for defining agent skill definitions.
	//
	// This member is required.
	DescriptorType types.DescriptorType

	// The name of the registry record.
	//
	// This member is required.
	Name *string

	// The identifier of the registry where the record will be created. You can
	// specify either the Amazon Resource Name (ARN) or the ID of the registry.
	//
	// This member is required.
	RegistryId *string

	// A unique, case-sensitive identifier to ensure that the API request completes no
	// more than one time. If you don't specify this field, a value is randomly
	// generated for you. If this token matches a previous request, the service ignores
	// the request, but doesn't return an error. For more information, see [Ensuring idempotency].
	//
	// [Ensuring idempotency]: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html
	ClientToken *string

	// A description of the registry record.
	Description *string

	// The descriptor-type-specific configuration containing the resource schema and
	// metadata. The structure of this field depends on the descriptorType you specify.
	Descriptors *types.Descriptors

	// The version of the registry record. Use this to track different versions of the
	// record's content.
	RecordVersion *string

	// The configuration for synchronizing registry record metadata from an external
	// source, such as a URL-based MCP server.
	SynchronizationConfiguration *types.SynchronizationConfiguration

	// The type of synchronization to use for keeping the record metadata up to date
	// from an external source. Possible values include FROM_URL and NONE .
	SynchronizationType types.SynchronizationType

	noSmithyDocumentSerde
}

type CreateRegistryRecordOutput struct {

	// The Amazon Resource Name (ARN) of the created registry record.
	//
	// This member is required.
	RecordArn *string

	// The status of the registry record. Set to CREATING while the asynchronous
	// workflow is in progress.
	//
	// This member is required.
	Status types.RegistryRecordStatus

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationCreateRegistryRecordMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestjson1_serializeOpCreateRegistryRecord{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpCreateRegistryRecord{}, 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_opCreateRegistryRecordMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpCreateRegistryRecordValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "CreateRegistryRecord"), 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_initializeOpCreateRegistryRecord struct {
	tokenProvider IdempotencyTokenProvider
}

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

func (m *idempotencyToken_initializeOpCreateRegistryRecord) 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.(*CreateRegistryRecordInput)
	if !ok {
		return out, metadata, fmt.Errorf("expected middleware input to be of type *CreateRegistryRecordInput ")
	}

	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_opCreateRegistryRecordMiddleware(stack *middleware.Stack, cfg Options) error {
	return stack.Initialize.Add(&idempotencyToken_initializeOpCreateRegistryRecord{tokenProvider: cfg.IdempotencyTokenProvider}, middleware.Before)
}
