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

package signin

import (
	"context"
	"fmt"
	"github.com/aws/aws-sdk-go-v2/service/signin/types"
	smithy "github.com/aws/smithy-go"
	"github.com/aws/smithy-go/middleware"
)

type validateOpCreateOAuth2Token struct {
}

func (*validateOpCreateOAuth2Token) ID() string {
	return "OperationInputValidation"
}

func (m *validateOpCreateOAuth2Token) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
	out middleware.InitializeOutput, metadata middleware.Metadata, err error,
) {
	input, ok := in.Parameters.(*CreateOAuth2TokenInput)
	if !ok {
		return out, metadata, fmt.Errorf("unknown input parameters type %T", in.Parameters)
	}
	if err := validateOpCreateOAuth2TokenInput(input); err != nil {
		return out, metadata, err
	}
	return next.HandleInitialize(ctx, in)
}

func addOpCreateOAuth2TokenValidationMiddleware(stack *middleware.Stack) error {
	return stack.Initialize.Add(&validateOpCreateOAuth2Token{}, middleware.After)
}

func validateCreateOAuth2TokenRequestBody(v *types.CreateOAuth2TokenRequestBody) error {
	if v == nil {
		return nil
	}
	invalidParams := smithy.InvalidParamsError{Context: "CreateOAuth2TokenRequestBody"}
	if v.ClientId == nil {
		invalidParams.Add(smithy.NewErrParamRequired("ClientId"))
	}
	if v.GrantType == nil {
		invalidParams.Add(smithy.NewErrParamRequired("GrantType"))
	}
	if invalidParams.Len() > 0 {
		return invalidParams
	} else {
		return nil
	}
}

func validateOpCreateOAuth2TokenInput(v *CreateOAuth2TokenInput) error {
	if v == nil {
		return nil
	}
	invalidParams := smithy.InvalidParamsError{Context: "CreateOAuth2TokenInput"}
	if v.TokenInput == nil {
		invalidParams.Add(smithy.NewErrParamRequired("TokenInput"))
	} else if v.TokenInput != nil {
		if err := validateCreateOAuth2TokenRequestBody(v.TokenInput); err != nil {
			invalidParams.AddNested("TokenInput", err.(smithy.InvalidParamsError))
		}
	}
	if invalidParams.Len() > 0 {
		return invalidParams
	} else {
		return nil
	}
}
