// Code generated by go-swagger; DO NOT EDIT.

// (c) 2012-2020 by Taxnexus, Inc.
// All rights reserved worldwide.
// Proprietary product; unlicensed use is not allowed

package sfgate_models

import (
	"context"
	stderrors "errors"
	"strconv"

	"github.com/go-openapi/errors"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag/jsonutils"
	"github.com/go-openapi/swag/typeutils"
)

// User user
//
// swagger:model User
type User struct {

	// API Gateway URL
	APIGatewayURL *string `json:"APIGatewayURL,omitempty"`

	// API Gateway User
	APIGatewayUser *string `json:"APIGatewayUser,omitempty"`

	// API Key
	APIKey *string `json:"APIKey,omitempty"`

	// About Me
	AboutMe *string `json:"AboutMe,omitempty"`

	// Account ID
	AccountID *string `json:"AccountID,omitempty"`

	// address
	Address *Address `json:"Address,omitempty"`

	// Alias
	Alias *string `json:"Alias,omitempty"`

	// Auth0 User Id
	Auth0UserID *string `json:"Auth0UserID,omitempty"`

	// Nickname
	CommunityNickname *string `json:"CommunityNickname,omitempty"`

	// Company Name
	CompanyName *string `json:"CompanyName,omitempty"`

	// Contact
	ContactID *string `json:"ContactID,omitempty"`

	// Created User ID
	CreatedByID *string `json:"CreatedByID,omitempty"`

	// Date Created
	CreatedDate *string `json:"CreatedDate,omitempty"`

	// Delegated Approver
	DelegatedApproverID *string `json:"DelegatedApproverID,omitempty"`

	// Department
	Department *string `json:"Department,omitempty"`

	// Division
	Division *string `json:"Division,omitempty"`

	// Email address
	Email *string `json:"Email,omitempty"`

	// Employee Number
	EmployeeNumber *string `json:"EmployeeNumber,omitempty"`

	// Time day ends
	EndOfDay *string `json:"EndOfDay,omitempty"`

	// Environment
	Environment *string `json:"Environment,omitempty"`

	// Extension
	Extension *string `json:"Extension,omitempty"`

	// Account
	ExternalAccount *string `json:"ExternalAccount,omitempty"`

	// Fabric API Key
	FabricAPIKey *string `json:"FabricAPIKey,omitempty"`

	// Fax
	Fax *string `json:"Fax,omitempty"`

	// The first name
	FirstName *string `json:"FirstName,omitempty"`

	// Allow Forecasting
	ForecastEnabled *bool `json:"ForecastEnabled,omitempty"`

	// Full Photo URL
	FullPhotoURL *string `json:"FullPhotoURL,omitempty"`

	// GitHub
	GitHub *string `json:"GitHub,omitempty"`

	// Record ID
	ID string `json:"ID,omitempty"`

	// Active
	IsActive *bool `json:"IsActive,omitempty"`

	// Is the user enabled for Communities?
	IsPortalEnabled *bool `json:"IsPortalEnabled,omitempty"`

	// Has Profile Photo
	IsProfilePhotoActive *bool `json:"IsProfilePhotoActive,omitempty"`

	// is system controlled
	IsSystemControlled *bool `json:"IsSystemControlled,omitempty"`

	// IP address of last login
	LastIP *string `json:"LastIP,omitempty"`

	// Last login time
	LastLogin *string `json:"LastLogin,omitempty"`

	// Last Modified User ID
	LastModifiedByID *string `json:"LastModifiedByID,omitempty"`

	// Last Modified Date
	LastModifiedDate *string `json:"LastModifiedDate,omitempty"`

	// The Last Name
	LastName *string `json:"LastName,omitempty"`

	// LinkedIn
	LinkedIn *string `json:"LinkedIn,omitempty"`

	// Number of times user has logged in
	LoginCount *int64 `json:"LoginCount,omitempty"`

	// Manager
	ManagerID *string `json:"ManagerID,omitempty"`

	// Mobile
	MobilePhone *string `json:"MobilePhone,omitempty"`

	// Name
	Name *string `json:"Name,omitempty"`

	// Out of office message
	OutOfOfficeMessage *string `json:"OutOfOfficeMessage,omitempty"`

	// Phone
	Phone *string `json:"Phone,omitempty"`

	// Portal Role Level
	PortalRole *string `json:"PortalRole,omitempty"`

	// Profile
	ProfileID *string `json:"ProfileID,omitempty"`

	// Info Emails
	ReceivesAdminEmails *bool `json:"ReceivesAdminEmails,omitempty"`

	// Admin Info Emails
	ReceivesAdminInfoEmails *bool `json:"ReceivesAdminInfoEmails,omitempty"`

	// Info Emails
	ReceivesInfoEmails *bool `json:"ReceivesInfoEmails,omitempty"`

	// Email Sender Address
	SenderEmail *string `json:"SenderEmail,omitempty"`

	// Email Sender Name
	SenderName *string `json:"SenderName,omitempty"`

	// Email Signature
	Signature *string `json:"Signature,omitempty"`

	// Small Photo URL
	SmallPhotoURL *string `json:"SmallPhotoURL,omitempty"`

	// The time day starts
	StartOfDay *string `json:"StartOfDay,omitempty"`

	// Status
	Status *string `json:"Status,omitempty"`

	// Tenant ID associated with this user
	TenantID *string `json:"TenantID,omitempty"`

	// tenant users
	TenantUsers []*TenantUser `json:"TenantUsers"`

	// Time Zone
	TimeZone *string `json:"TimeZone,omitempty"`

	// Title
	Title *string `json:"Title,omitempty"`

	// Twitter
	Twitter *string `json:"Twitter,omitempty"`

	// Role
	UserRoleID *string `json:"UserRoleID,omitempty"`

	// user roles
	UserRoles []*UserRole `json:"UserRoles"`

	// User Type
	UserType *string `json:"UserType,omitempty"`

	// Username
	Username *string `json:"Username,omitempty"`
}

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

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

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

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

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

func (m *User) validateAddress(formats strfmt.Registry) error {
	if typeutils.IsZero(m.Address) { // not required
		return nil
	}

	if m.Address != nil {
		if err := m.Address.Validate(formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("Address")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("Address")
			}

			return err
		}
	}

	return nil
}

func (m *User) validateTenantUsers(formats strfmt.Registry) error {
	if typeutils.IsZero(m.TenantUsers) { // not required
		return nil
	}

	for i := 0; i < len(m.TenantUsers); i++ {
		if typeutils.IsZero(m.TenantUsers[i]) { // not required
			continue
		}

		if m.TenantUsers[i] != nil {
			if err := m.TenantUsers[i].Validate(formats); err != nil {
				ve := new(errors.Validation)
				if stderrors.As(err, &ve) {
					return ve.ValidateName("TenantUsers" + "." + strconv.Itoa(i))
				}
				ce := new(errors.CompositeError)
				if stderrors.As(err, &ce) {
					return ce.ValidateName("TenantUsers" + "." + strconv.Itoa(i))
				}

				return err
			}
		}

	}

	return nil
}

func (m *User) validateUserRoles(formats strfmt.Registry) error {
	if typeutils.IsZero(m.UserRoles) { // not required
		return nil
	}

	for i := 0; i < len(m.UserRoles); i++ {
		if typeutils.IsZero(m.UserRoles[i]) { // not required
			continue
		}

		if m.UserRoles[i] != nil {
			if err := m.UserRoles[i].Validate(formats); err != nil {
				ve := new(errors.Validation)
				if stderrors.As(err, &ve) {
					return ve.ValidateName("UserRoles" + "." + strconv.Itoa(i))
				}
				ce := new(errors.CompositeError)
				if stderrors.As(err, &ce) {
					return ce.ValidateName("UserRoles" + "." + strconv.Itoa(i))
				}

				return err
			}
		}

	}

	return nil
}

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

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

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

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

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

func (m *User) contextValidateAddress(ctx context.Context, formats strfmt.Registry) error {

	if m.Address != nil {

		if typeutils.IsZero(m.Address) { // not required
			return nil
		}

		if err := m.Address.ContextValidate(ctx, formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("Address")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("Address")
			}

			return err
		}
	}

	return nil
}

func (m *User) contextValidateTenantUsers(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.TenantUsers); i++ {

		if m.TenantUsers[i] != nil {

			if typeutils.IsZero(m.TenantUsers[i]) { // not required
				return nil
			}

			if err := m.TenantUsers[i].ContextValidate(ctx, formats); err != nil {
				ve := new(errors.Validation)
				if stderrors.As(err, &ve) {
					return ve.ValidateName("TenantUsers" + "." + strconv.Itoa(i))
				}
				ce := new(errors.CompositeError)
				if stderrors.As(err, &ce) {
					return ce.ValidateName("TenantUsers" + "." + strconv.Itoa(i))
				}

				return err
			}
		}

	}

	return nil
}

func (m *User) contextValidateUserRoles(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.UserRoles); i++ {

		if m.UserRoles[i] != nil {

			if typeutils.IsZero(m.UserRoles[i]) { // not required
				return nil
			}

			if err := m.UserRoles[i].ContextValidate(ctx, formats); err != nil {
				ve := new(errors.Validation)
				if stderrors.As(err, &ve) {
					return ve.ValidateName("UserRoles" + "." + strconv.Itoa(i))
				}
				ce := new(errors.CompositeError)
				if stderrors.As(err, &ce) {
					return ce.ValidateName("UserRoles" + "." + strconv.Itoa(i))
				}

				return err
			}
		}

	}

	return nil
}

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

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