// Code generated by go-swagger; DO NOT EDIT.

package models

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
	"context"

	"github.com/go-openapi/errors"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag"
	"github.com/go-openapi/validate"
)

// S3BlobStoreAPIBucketConfiguration s3 blob store Api bucket configuration
//
// swagger:model S3BlobStoreApiBucketConfiguration
type S3BlobStoreAPIBucketConfiguration struct {

	// A custom endpoint URL, signer type and whether path style access is enabled
	AdvancedBucketConnection *S3BlobStoreAPIAdvancedBucketConnection `json:"advancedBucketConnection,omitempty"`

	// Details of the S3 bucket such as name and region
	// Required: true
	// Read Only: true
	Bucket *S3BlobStoreAPIBucket `json:"bucket"`

	// Security details for granting access the S3 API
	BucketSecurity *S3BlobStoreAPIBucketSecurity `json:"bucketSecurity,omitempty"`

	// The type of encryption to use if any
	// Read Only: true
	Encryption *S3BlobStoreAPIEncryption `json:"encryption,omitempty"`
}

// Validate validates this s3 blob store Api bucket configuration
func (m *S3BlobStoreAPIBucketConfiguration) Validate(formats strfmt.Registry) error {
	var res []error

	if err := m.validateAdvancedBucketConnection(formats); err != nil {
		res = append(res, err)
	}

	if err := m.validateBucket(formats); err != nil {
		res = append(res, err)
	}

	if err := m.validateBucketSecurity(formats); err != nil {
		res = append(res, err)
	}

	if err := m.validateEncryption(formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

func (m *S3BlobStoreAPIBucketConfiguration) validateAdvancedBucketConnection(formats strfmt.Registry) error {
	if swag.IsZero(m.AdvancedBucketConnection) { // not required
		return nil
	}

	if m.AdvancedBucketConnection != nil {
		if err := m.AdvancedBucketConnection.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("advancedBucketConnection")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("advancedBucketConnection")
			}
			return err
		}
	}

	return nil
}

func (m *S3BlobStoreAPIBucketConfiguration) validateBucket(formats strfmt.Registry) error {

	if err := validate.Required("bucket", "body", m.Bucket); err != nil {
		return err
	}

	if m.Bucket != nil {
		if err := m.Bucket.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("bucket")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("bucket")
			}
			return err
		}
	}

	return nil
}

func (m *S3BlobStoreAPIBucketConfiguration) validateBucketSecurity(formats strfmt.Registry) error {
	if swag.IsZero(m.BucketSecurity) { // not required
		return nil
	}

	if m.BucketSecurity != nil {
		if err := m.BucketSecurity.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("bucketSecurity")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("bucketSecurity")
			}
			return err
		}
	}

	return nil
}

func (m *S3BlobStoreAPIBucketConfiguration) validateEncryption(formats strfmt.Registry) error {
	if swag.IsZero(m.Encryption) { // not required
		return nil
	}

	if m.Encryption != nil {
		if err := m.Encryption.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("encryption")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("encryption")
			}
			return err
		}
	}

	return nil
}

// ContextValidate validate this s3 blob store Api bucket configuration based on the context it is used
func (m *S3BlobStoreAPIBucketConfiguration) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

	if err := m.contextValidateAdvancedBucketConnection(ctx, formats); err != nil {
		res = append(res, err)
	}

	if err := m.contextValidateBucket(ctx, formats); err != nil {
		res = append(res, err)
	}

	if err := m.contextValidateBucketSecurity(ctx, formats); err != nil {
		res = append(res, err)
	}

	if err := m.contextValidateEncryption(ctx, formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

func (m *S3BlobStoreAPIBucketConfiguration) contextValidateAdvancedBucketConnection(ctx context.Context, formats strfmt.Registry) error {

	if m.AdvancedBucketConnection != nil {
		if err := m.AdvancedBucketConnection.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("advancedBucketConnection")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("advancedBucketConnection")
			}
			return err
		}
	}

	return nil
}

func (m *S3BlobStoreAPIBucketConfiguration) contextValidateBucket(ctx context.Context, formats strfmt.Registry) error {

	if m.Bucket != nil {
		if err := m.Bucket.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("bucket")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("bucket")
			}
			return err
		}
	}

	return nil
}

func (m *S3BlobStoreAPIBucketConfiguration) contextValidateBucketSecurity(ctx context.Context, formats strfmt.Registry) error {

	if m.BucketSecurity != nil {
		if err := m.BucketSecurity.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("bucketSecurity")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("bucketSecurity")
			}
			return err
		}
	}

	return nil
}

func (m *S3BlobStoreAPIBucketConfiguration) contextValidateEncryption(ctx context.Context, formats strfmt.Registry) error {

	if m.Encryption != nil {
		if err := m.Encryption.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("encryption")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("encryption")
			}
			return err
		}
	}

	return nil
}

// MarshalBinary interface implementation
func (m *S3BlobStoreAPIBucketConfiguration) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}

// UnmarshalBinary interface implementation
func (m *S3BlobStoreAPIBucketConfiguration) UnmarshalBinary(b []byte) error {
	var res S3BlobStoreAPIBucketConfiguration
	if err := swag.ReadJSON(b, &res); err != nil {
		return err
	}
	*m = res
	return nil
}
