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

// UserAuthenticationInfo user authentication info
//
// swagger:model UserAuthenticationInfo
type UserAuthenticationInfo struct {

	// User Account ID
	// Required: true
	AccountID *string `json:"accountID"`

	// Map of internal capabilities the user has access to and their level of access
	Capabilities ResourceAccess `json:"capabilities,omitempty"`

	// Workaround for AT event tracker
	CredentialType string `json:"credentialType,omitempty"`

	// Map of the user's CRNs to their level of access
	CrnAccess ResourceAccess `json:"crnAccess,omitempty"`

	// User Email
	// Required: true
	Email *string `json:"email"`

	// User ID
	// Required: true
	ID *string `json:"id"`

	// Member of the following tenants
	MemberOf []string `json:"memberOf"`

	// User Name
	// Required: true
	Name *string `json:"name"`

	// OAuth2 Token
	// Required: true
	Token *Token `json:"token"`
}

// Validate validates this user authentication info
func (m *UserAuthenticationInfo) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

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

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

func (m *UserAuthenticationInfo) validateAccountID(formats strfmt.Registry) error {

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

	return nil
}

func (m *UserAuthenticationInfo) validateCapabilities(formats strfmt.Registry) error {
	if swag.IsZero(m.Capabilities) { // not required
		return nil
	}

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

	return nil
}

func (m *UserAuthenticationInfo) validateCrnAccess(formats strfmt.Registry) error {
	if swag.IsZero(m.CrnAccess) { // not required
		return nil
	}

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

	return nil
}

func (m *UserAuthenticationInfo) validateEmail(formats strfmt.Registry) error {

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

	return nil
}

func (m *UserAuthenticationInfo) validateID(formats strfmt.Registry) error {

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

	return nil
}

func (m *UserAuthenticationInfo) validateName(formats strfmt.Registry) error {

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

	return nil
}

func (m *UserAuthenticationInfo) validateToken(formats strfmt.Registry) error {

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

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

	return nil
}

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

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

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

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

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

func (m *UserAuthenticationInfo) contextValidateCapabilities(ctx context.Context, formats strfmt.Registry) error {

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

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

	return nil
}

func (m *UserAuthenticationInfo) contextValidateCrnAccess(ctx context.Context, formats strfmt.Registry) error {

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

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

	return nil
}

func (m *UserAuthenticationInfo) contextValidateToken(ctx context.Context, formats strfmt.Registry) error {

	if m.Token != nil {

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

	return nil
}

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

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