// THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.

package s3

import (
	"github.com/ks3sdklib/aws-sdk-go/aws"
	"github.com/ks3sdklib/aws-sdk-go/internal/protocol/restxml"
	"github.com/ks3sdklib/aws-sdk-go/internal/signer/v2"
)

// S3 is a client for Amazon S3.
type S3 struct {
	*aws.Service
}

// Used for custom service initialization logic
var initService func(*aws.Service)

// Used for custom request initialization logic
var initRequest func(*aws.Request)

// New returns a new S3 client.
func New(config *aws.Config) *S3 {
	service := &aws.Service{
		Config:      aws.DefaultConfig.Merge(config),
		ServiceName: "s3",
		APIVersion:  "2006-03-01",
	}
	service.Initialize()

	// Handlers
	service.Handlers.Sign.PushBack(v2.Sign)
	service.Handlers.Build.PushBack(restxml.Build)
	//service.Handlers.Build.PushBack(aws.ContentTypeHandler)
	service.Handlers.Unmarshal.PushBack(restxml.Unmarshal)
	service.Handlers.UnmarshalMeta.PushBack(restxml.UnmarshalMeta)
	service.Handlers.UnmarshalError.PushBack(restxml.UnmarshalError)

	// Run custom service initialization if present
	if initService != nil {
		initService(service)
	}

	return &S3{service}
}

// newRequest creates a new request for a S3 operation and runs any
// custom request initialization.
func (c *S3) newRequest(op *aws.Operation, params, data interface{}) *aws.Request {
	req := aws.NewRequest(c.Service, op, params, data)
	updateHostWithBucket(req)
	// Run custom request initialization if present
	if initRequest != nil {
		initRequest(req)
	}
	return req
}
