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

package ecr

import (
	"context"
	"github.com/aws/aws-sdk-go-v2/service/ecr/schemas"
	smithy "github.com/aws/smithy-go"
	"github.com/aws/smithy-go/middleware"
)

// Validates an existing pull through cache rule for an upstream registry that
// requires authentication. This will retrieve the contents of the Amazon Web
// Services Secrets Manager secret, verify the syntax, and then validate that
// authentication to the upstream registry is successful.
func (c *Client) ValidatePullThroughCacheRule(ctx context.Context, params *ValidatePullThroughCacheRuleInput, optFns ...func(*Options)) (*ValidatePullThroughCacheRuleOutput, error) {
	if params == nil {
		params = &ValidatePullThroughCacheRuleInput{}
	}

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

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

type ValidatePullThroughCacheRuleInput struct {

	// The repository name prefix associated with the pull through cache rule.
	//
	// This member is required.
	EcrRepositoryPrefix *string

	// The registry ID associated with the pull through cache rule. If you do not
	// specify a registry, the default registry is assumed.
	RegistryId *string

	noSmithyDocumentSerde
}

func (v *ValidatePullThroughCacheRuleInput) Serialize(s smithy.ShapeSerializer) {
	s.WriteStruct(schemas.ValidatePullThroughCacheRuleRequest)
	v.SerializeMembers(s)
	s.CloseStruct()
}

func (v *ValidatePullThroughCacheRuleInput) SerializeMembers(s smithy.ShapeSerializer) {
	if v.EcrRepositoryPrefix != nil {
		s.WriteString(schemas.ValidatePullThroughCacheRuleRequest_ecrRepositoryPrefix, *v.EcrRepositoryPrefix)
	}
	if v.RegistryId != nil {
		s.WriteString(schemas.ValidatePullThroughCacheRuleRequest_registryId, *v.RegistryId)
	}
}

type ValidatePullThroughCacheRuleOutput struct {

	// The Amazon Resource Name (ARN) of the Amazon Web Services Secrets Manager
	// secret associated with the pull through cache rule.
	CredentialArn *string

	// The ARN of the IAM role associated with the pull through cache rule.
	CustomRoleArn *string

	// The Amazon ECR repository prefix associated with the pull through cache rule.
	EcrRepositoryPrefix *string

	// The reason the validation failed. For more details about possible causes and
	// how to address them, see [Using pull through cache rules]in the Amazon Elastic Container Registry User Guide.
	//
	// [Using pull through cache rules]: https://docs.aws.amazon.com/AmazonECR/latest/userguide/pull-through-cache.html
	Failure *string

	// Whether or not the pull through cache rule was validated. If true , Amazon ECR
	// was able to reach the upstream registry and authentication was successful. If
	// false , there was an issue and validation failed. The failure reason indicates
	// the cause.
	IsValid bool

	// The registry ID associated with the request.
	RegistryId *string

	// The upstream registry URL associated with the pull through cache rule.
	UpstreamRegistryUrl *string

	// The upstream repository prefix associated with the pull through cache rule.
	UpstreamRepositoryPrefix *string

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

	noSmithyDocumentSerde
}

func (v *ValidatePullThroughCacheRuleOutput) Serialize(s smithy.ShapeSerializer) {
	s.WriteStruct(schemas.ValidatePullThroughCacheRuleResponse)
	v.SerializeMembers(s)
	s.CloseStruct()
}

func (v *ValidatePullThroughCacheRuleOutput) SerializeMembers(s smithy.ShapeSerializer) {
	if v.CredentialArn != nil {
		s.WriteString(schemas.ValidatePullThroughCacheRuleResponse_credentialArn, *v.CredentialArn)
	}
	if v.CustomRoleArn != nil {
		s.WriteString(schemas.ValidatePullThroughCacheRuleResponse_customRoleArn, *v.CustomRoleArn)
	}
	if v.EcrRepositoryPrefix != nil {
		s.WriteString(schemas.ValidatePullThroughCacheRuleResponse_ecrRepositoryPrefix, *v.EcrRepositoryPrefix)
	}
	if v.Failure != nil {
		s.WriteString(schemas.ValidatePullThroughCacheRuleResponse_failure, *v.Failure)
	}
	if v.IsValid != false {
		s.WriteBool(schemas.ValidatePullThroughCacheRuleResponse_isValid, v.IsValid)
	}
	if v.RegistryId != nil {
		s.WriteString(schemas.ValidatePullThroughCacheRuleResponse_registryId, *v.RegistryId)
	}
	if v.UpstreamRegistryUrl != nil {
		s.WriteString(schemas.ValidatePullThroughCacheRuleResponse_upstreamRegistryUrl, *v.UpstreamRegistryUrl)
	}
	if v.UpstreamRepositoryPrefix != nil {
		s.WriteString(schemas.ValidatePullThroughCacheRuleResponse_upstreamRepositoryPrefix, *v.UpstreamRepositoryPrefix)
	}
}
func (v *ValidatePullThroughCacheRuleOutput) Deserialize(d smithy.ShapeDeserializer) error {
	return smithy.ReadStruct(d, schemas.ValidatePullThroughCacheRuleResponse, func(s *smithy.Schema) error {
		switch s {
		case schemas.ValidatePullThroughCacheRuleResponse_credentialArn:
			v.CredentialArn = new(string)
			return d.ReadString(schemas.ValidatePullThroughCacheRuleResponse_credentialArn, v.CredentialArn)
		case schemas.ValidatePullThroughCacheRuleResponse_customRoleArn:
			v.CustomRoleArn = new(string)
			return d.ReadString(schemas.ValidatePullThroughCacheRuleResponse_customRoleArn, v.CustomRoleArn)
		case schemas.ValidatePullThroughCacheRuleResponse_ecrRepositoryPrefix:
			v.EcrRepositoryPrefix = new(string)
			return d.ReadString(schemas.ValidatePullThroughCacheRuleResponse_ecrRepositoryPrefix, v.EcrRepositoryPrefix)
		case schemas.ValidatePullThroughCacheRuleResponse_failure:
			v.Failure = new(string)
			return d.ReadString(schemas.ValidatePullThroughCacheRuleResponse_failure, v.Failure)
		case schemas.ValidatePullThroughCacheRuleResponse_isValid:
			return d.ReadBool(schemas.ValidatePullThroughCacheRuleResponse_isValid, &v.IsValid)
		case schemas.ValidatePullThroughCacheRuleResponse_registryId:
			v.RegistryId = new(string)
			return d.ReadString(schemas.ValidatePullThroughCacheRuleResponse_registryId, v.RegistryId)
		case schemas.ValidatePullThroughCacheRuleResponse_upstreamRegistryUrl:
			v.UpstreamRegistryUrl = new(string)
			return d.ReadString(schemas.ValidatePullThroughCacheRuleResponse_upstreamRegistryUrl, v.UpstreamRegistryUrl)
		case schemas.ValidatePullThroughCacheRuleResponse_upstreamRepositoryPrefix:
			v.UpstreamRepositoryPrefix = new(string)
			return d.ReadString(schemas.ValidatePullThroughCacheRuleResponse_upstreamRepositoryPrefix, v.UpstreamRepositoryPrefix)
		}
		return nil
	})
}
func (c *Client) addOperationValidatePullThroughCacheRuleMiddlewares(stack *middleware.Stack, options Options) (err error) {
	if err := stack.Serialize.Add(&serializeRequestMiddleware{options: &options, operationSchema: smithy.NewOperationSchema(schemas.ValidatePullThroughCacheRule, schemas.ValidatePullThroughCacheRuleRequest, schemas.ValidatePullThroughCacheRuleResponse)}, middleware.After); err != nil {
		return err
	}
	if err := stack.Deserialize.Add(&deserializeResponseMiddleware{options: &options, operationSchema: smithy.NewOperationSchema(schemas.ValidatePullThroughCacheRule, schemas.ValidatePullThroughCacheRuleRequest, schemas.ValidatePullThroughCacheRuleResponse), output: &ValidatePullThroughCacheRuleOutput{}}, middleware.After); 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 = addCredentialSource(stack, options); err != nil {
		return err
	}
	if err = addOpValidatePullThroughCacheRuleValidationMiddleware(stack); 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
}
