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

// APIGetDeviceActivationResponse api get device activation response
//
// swagger:model apiGetDeviceActivationResponse
type APIGetDeviceActivationResponse struct {

	// Device activation object.
	DeviceActivation *APIDeviceActivation `json:"deviceActivation,omitempty"`

	// Join-Server context.
	// A non-empty value indicatest that ChirpStack does not have access to
	// the AppSKey and that the encryption / decryption of the payloads is
	// the responsibility of the end-application.
	JoinServerContext *CommonJoinServerContext `json:"joinServerContext,omitempty"`
}

// Validate validates this api get device activation response
func (m *APIGetDeviceActivationResponse) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *APIGetDeviceActivationResponse) validateDeviceActivation(formats strfmt.Registry) error {
	if swag.IsZero(m.DeviceActivation) { // not required
		return nil
	}

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

	return nil
}

func (m *APIGetDeviceActivationResponse) validateJoinServerContext(formats strfmt.Registry) error {
	if swag.IsZero(m.JoinServerContext) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

func (m *APIGetDeviceActivationResponse) contextValidateDeviceActivation(ctx context.Context, formats strfmt.Registry) error {

	if m.DeviceActivation != nil {

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

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

	return nil
}

func (m *APIGetDeviceActivationResponse) contextValidateJoinServerContext(ctx context.Context, formats strfmt.Registry) error {

	if m.JoinServerContext != nil {

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

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

	return nil
}

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

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