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

// APIGcpPubSubIntegration api gcp pub sub integration
//
// swagger:model apiGcpPubSubIntegration
type APIGcpPubSubIntegration struct {

	// Application ID (UUID).
	ApplicationID string `json:"applicationId,omitempty"`

	// Credentials file.
	// This IAM service-account credentials file (JSON) must have the following
	// Pub/Sub roles:
	// * Pub/Sub Publisher
	CredentialsFile string `json:"credentialsFile,omitempty"`

	// Encoding.
	Encoding *APIEncoding `json:"encoding,omitempty"`

	// Project ID.
	ProjectID string `json:"projectId,omitempty"`

	// Topic name.
	// This is the name of the Pub/Sub topic.
	TopicName string `json:"topicName,omitempty"`
}

// Validate validates this api gcp pub sub integration
func (m *APIGcpPubSubIntegration) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *APIGcpPubSubIntegration) validateEncoding(formats strfmt.Registry) error {
	if swag.IsZero(m.Encoding) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this api gcp pub sub integration based on the context it is used
func (m *APIGcpPubSubIntegration) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

func (m *APIGcpPubSubIntegration) contextValidateEncoding(ctx context.Context, formats strfmt.Registry) error {

	if m.Encoding != nil {

		if swag.IsZero(m.Encoding) { // not required
			return nil
		}

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

	return nil
}

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

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