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

// CommonJoinServerContext Join-Server context.
//
// swagger:model commonJoinServerContext
type CommonJoinServerContext struct {

	// AppSKey envelope.
	AppSKey *CommonKeyEnvelope `json:"appSKey,omitempty"`

	// Session-key ID.
	SessionKeyID string `json:"sessionKeyId,omitempty"`
}

// Validate validates this common join server context
func (m *CommonJoinServerContext) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *CommonJoinServerContext) validateAppSKey(formats strfmt.Registry) error {
	if swag.IsZero(m.AppSKey) { // not required
		return nil
	}

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

	return nil
}

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

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

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

func (m *CommonJoinServerContext) contextValidateAppSKey(ctx context.Context, formats strfmt.Registry) error {

	if m.AppSKey != nil {

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

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

	return nil
}

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

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