package http

import (
	
	
	
	
)

// MinimumProtocolError is an error type indicating that the established connection did not meet the expected minimum
// HTTP protocol version.
type MinimumProtocolError struct {
	proto              string
	expectedProtoMajor int
	expectedProtoMinor int
}

// Error returns the error message.
func ( *MinimumProtocolError) () string {
	return fmt.Sprintf("operation requires minimum HTTP protocol of HTTP/%d.%d, but was %s",
		.expectedProtoMajor, .expectedProtoMinor, .proto)
}

// RequireMinimumProtocol is a deserialization middleware that asserts that the established HTTP connection
// meets the minimum major ad minor version.
type RequireMinimumProtocol struct {
	ProtoMajor int
	ProtoMinor int
}

// AddRequireMinimumProtocol adds the RequireMinimumProtocol middleware to the stack using the provided minimum
// protocol major and minor version.
func ( *middleware.Stack, ,  int) error {
	return .Deserialize.Insert(&RequireMinimumProtocol{
		ProtoMajor: ,
		ProtoMinor: ,
	}, "OperationDeserializer", middleware.Before)
}

// ID returns the middleware identifier string.
func ( *RequireMinimumProtocol) () string {
	return "RequireMinimumProtocol"
}

// HandleDeserialize asserts that the established connection is a HTTP connection with the minimum major and minor
// protocol version.
func ( *RequireMinimumProtocol) (
	 context.Context,  middleware.DeserializeInput,  middleware.DeserializeHandler,
) (
	 middleware.DeserializeOutput,  middleware.Metadata,  error,
) {
	, ,  = .HandleDeserialize(, )
	if  != nil {
		return , , 
	}

	,  := .RawResponse.(*Response)
	if ! {
		return , , fmt.Errorf("unknown transport type: %T", .RawResponse)
	}

	if !strings.HasPrefix(.Proto, "HTTP") {
		return , , &MinimumProtocolError{
			proto:              .Proto,
			expectedProtoMajor: .ProtoMajor,
			expectedProtoMinor: .ProtoMinor,
		}
	}

	if .ProtoMajor < .ProtoMajor || .ProtoMinor < .ProtoMinor {
		return , , &MinimumProtocolError{
			proto:              .Proto,
			expectedProtoMajor: .ProtoMajor,
			expectedProtoMinor: .ProtoMinor,
		}
	}

	return , , 
}