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

// APIGateway api gateway
//
// swagger:model apiGateway
type APIGateway struct {

	// Description.
	Description string `json:"description,omitempty"`

	// Gateway ID (EUI64).
	GatewayID string `json:"gatewayId,omitempty"`

	// Gateway location.
	Location *CommonLocation `json:"location,omitempty"`

	// Metadata (provided by the gateway).
	Metadata map[string]string `json:"metadata,omitempty"`

	// Name.
	Name string `json:"name,omitempty"`

	// Stats interval (seconds).
	// This defines the expected interval in which the gateway sends its
	// statistics.
	StatsInterval int64 `json:"statsInterval,omitempty"`

	// Tags.
	Tags map[string]string `json:"tags,omitempty"`

	// Tenant ID (UUID).
	TenantID string `json:"tenantId,omitempty"`
}

// Validate validates this api gateway
func (m *APIGateway) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *APIGateway) validateLocation(formats strfmt.Registry) error {
	if swag.IsZero(m.Location) { // not required
		return nil
	}

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

	return nil
}

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

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

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

func (m *APIGateway) contextValidateLocation(ctx context.Context, formats strfmt.Registry) error {

	if m.Location != nil {

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

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

	return nil
}

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

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