// 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"
	"time"
)

// Updates an existing pull through cache rule.
func (c *Client) UpdatePullThroughCacheRule(ctx context.Context, params *UpdatePullThroughCacheRuleInput, optFns ...func(*Options)) (*UpdatePullThroughCacheRuleOutput, error) {
	if params == nil {
		params = &UpdatePullThroughCacheRuleInput{}
	}

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

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

type UpdatePullThroughCacheRuleInput struct {

	// The repository name prefix to use when caching images from the source registry.
	//
	// This member is required.
	EcrRepositoryPrefix *string

	// The Amazon Resource Name (ARN) of the Amazon Web Services Secrets Manager
	// secret that identifies the credentials to authenticate to the upstream registry.
	CredentialArn *string

	// Amazon Resource Name (ARN) of the IAM role to be assumed by Amazon ECR to
	// authenticate to the ECR upstream registry. This role must be in the same account
	// as the registry that you are configuring.
	CustomRoleArn *string

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

	noSmithyDocumentSerde
}

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

func (v *UpdatePullThroughCacheRuleInput) SerializeMembers(s smithy.ShapeSerializer) {
	if v.CredentialArn != nil {
		s.WriteString(schemas.UpdatePullThroughCacheRuleRequest_credentialArn, *v.CredentialArn)
	}
	if v.CustomRoleArn != nil {
		s.WriteString(schemas.UpdatePullThroughCacheRuleRequest_customRoleArn, *v.CustomRoleArn)
	}
	if v.EcrRepositoryPrefix != nil {
		s.WriteString(schemas.UpdatePullThroughCacheRuleRequest_ecrRepositoryPrefix, *v.EcrRepositoryPrefix)
	}
	if v.RegistryId != nil {
		s.WriteString(schemas.UpdatePullThroughCacheRuleRequest_registryId, *v.RegistryId)
	}
}

type UpdatePullThroughCacheRuleOutput 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 registry ID associated with the request.
	RegistryId *string

	// The date and time, in JavaScript date format, when the pull through cache rule
	// was updated.
	UpdatedAt *time.Time

	// 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 *UpdatePullThroughCacheRuleOutput) Serialize(s smithy.ShapeSerializer) {
	s.WriteStruct(schemas.UpdatePullThroughCacheRuleResponse)
	v.SerializeMembers(s)
	s.CloseStruct()
}

func (v *UpdatePullThroughCacheRuleOutput) SerializeMembers(s smithy.ShapeSerializer) {
	if v.CredentialArn != nil {
		s.WriteString(schemas.UpdatePullThroughCacheRuleResponse_credentialArn, *v.CredentialArn)
	}
	if v.CustomRoleArn != nil {
		s.WriteString(schemas.UpdatePullThroughCacheRuleResponse_customRoleArn, *v.CustomRoleArn)
	}
	if v.EcrRepositoryPrefix != nil {
		s.WriteString(schemas.UpdatePullThroughCacheRuleResponse_ecrRepositoryPrefix, *v.EcrRepositoryPrefix)
	}
	if v.RegistryId != nil {
		s.WriteString(schemas.UpdatePullThroughCacheRuleResponse_registryId, *v.RegistryId)
	}
	if v.UpdatedAt != nil {
		s.WriteTime(schemas.UpdatePullThroughCacheRuleResponse_updatedAt, *v.UpdatedAt)
	}
	if v.UpstreamRepositoryPrefix != nil {
		s.WriteString(schemas.UpdatePullThroughCacheRuleResponse_upstreamRepositoryPrefix, *v.UpstreamRepositoryPrefix)
	}
}
func (v *UpdatePullThroughCacheRuleOutput) Deserialize(d smithy.ShapeDeserializer) error {
	return smithy.ReadStruct(d, schemas.UpdatePullThroughCacheRuleResponse, func(s *smithy.Schema) error {
		switch s {
		case schemas.UpdatePullThroughCacheRuleResponse_credentialArn:
			v.CredentialArn = new(string)
			return d.ReadString(schemas.UpdatePullThroughCacheRuleResponse_credentialArn, v.CredentialArn)
		case schemas.UpdatePullThroughCacheRuleResponse_customRoleArn:
			v.CustomRoleArn = new(string)
			return d.ReadString(schemas.UpdatePullThroughCacheRuleResponse_customRoleArn, v.CustomRoleArn)
		case schemas.UpdatePullThroughCacheRuleResponse_ecrRepositoryPrefix:
			v.EcrRepositoryPrefix = new(string)
			return d.ReadString(schemas.UpdatePullThroughCacheRuleResponse_ecrRepositoryPrefix, v.EcrRepositoryPrefix)
		case schemas.UpdatePullThroughCacheRuleResponse_registryId:
			v.RegistryId = new(string)
			return d.ReadString(schemas.UpdatePullThroughCacheRuleResponse_registryId, v.RegistryId)
		case schemas.UpdatePullThroughCacheRuleResponse_updatedAt:
			v.UpdatedAt = new(time.Time)
			return d.ReadTime(schemas.UpdatePullThroughCacheRuleResponse_updatedAt, v.UpdatedAt)
		case schemas.UpdatePullThroughCacheRuleResponse_upstreamRepositoryPrefix:
			v.UpstreamRepositoryPrefix = new(string)
			return d.ReadString(schemas.UpdatePullThroughCacheRuleResponse_upstreamRepositoryPrefix, v.UpstreamRepositoryPrefix)
		}
		return nil
	})
}
func (c *Client) addOperationUpdatePullThroughCacheRuleMiddlewares(stack *middleware.Stack, options Options) (err error) {
	if err := stack.Serialize.Add(&serializeRequestMiddleware{options: &options, operationSchema: smithy.NewOperationSchema(schemas.UpdatePullThroughCacheRule, schemas.UpdatePullThroughCacheRuleRequest, schemas.UpdatePullThroughCacheRuleResponse)}, middleware.After); err != nil {
		return err
	}
	if err := stack.Deserialize.Add(&deserializeResponseMiddleware{options: &options, operationSchema: smithy.NewOperationSchema(schemas.UpdatePullThroughCacheRule, schemas.UpdatePullThroughCacheRuleRequest, schemas.UpdatePullThroughCacheRuleResponse), output: &UpdatePullThroughCacheRuleOutput{}}, 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 = addOpUpdatePullThroughCacheRuleValidationMiddleware(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
}
