// Code generated by Fern. DO NOT EDIT.

package management

import (
	json "encoding/json"
	fmt "fmt"
	internal "github.com/auth0/go-auth0/v2/management/internal"
	big "math/big"
)

var (
	listUserGrantsOffsetPaginatedResponseContentFieldStart  = big.NewInt(1 << 0)
	listUserGrantsOffsetPaginatedResponseContentFieldLimit  = big.NewInt(1 << 1)
	listUserGrantsOffsetPaginatedResponseContentFieldTotal  = big.NewInt(1 << 2)
	listUserGrantsOffsetPaginatedResponseContentFieldGrants = big.NewInt(1 << 3)
)

type ListUserGrantsOffsetPaginatedResponseContent struct {
	Start  *float64     `json:"start,omitempty" url:"start,omitempty"`
	Limit  *float64     `json:"limit,omitempty" url:"limit,omitempty"`
	Total  *float64     `json:"total,omitempty" url:"total,omitempty"`
	Grants []*UserGrant `json:"grants,omitempty" url:"grants,omitempty"`

	// Private bitmask of fields set to an explicit value and therefore not to be omitted
	explicitFields *big.Int `json:"-" url:"-"`

	extraProperties map[string]interface{}
	rawJSON         json.RawMessage
}

func (l *ListUserGrantsOffsetPaginatedResponseContent) GetStart() float64 {
	if l == nil || l.Start == nil {
		return 0
	}
	return *l.Start
}

func (l *ListUserGrantsOffsetPaginatedResponseContent) GetLimit() float64 {
	if l == nil || l.Limit == nil {
		return 0
	}
	return *l.Limit
}

func (l *ListUserGrantsOffsetPaginatedResponseContent) GetTotal() float64 {
	if l == nil || l.Total == nil {
		return 0
	}
	return *l.Total
}

func (l *ListUserGrantsOffsetPaginatedResponseContent) GetGrants() []*UserGrant {
	if l == nil || l.Grants == nil {
		return nil
	}
	return l.Grants
}

func (l *ListUserGrantsOffsetPaginatedResponseContent) GetExtraProperties() map[string]interface{} {
	return l.extraProperties
}

func (l *ListUserGrantsOffsetPaginatedResponseContent) require(field *big.Int) {
	if l.explicitFields == nil {
		l.explicitFields = big.NewInt(0)
	}
	l.explicitFields.Or(l.explicitFields, field)
}

// SetStart sets the Start field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (l *ListUserGrantsOffsetPaginatedResponseContent) SetStart(start *float64) {
	l.Start = start
	l.require(listUserGrantsOffsetPaginatedResponseContentFieldStart)
}

// SetLimit sets the Limit field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (l *ListUserGrantsOffsetPaginatedResponseContent) SetLimit(limit *float64) {
	l.Limit = limit
	l.require(listUserGrantsOffsetPaginatedResponseContentFieldLimit)
}

// SetTotal sets the Total field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (l *ListUserGrantsOffsetPaginatedResponseContent) SetTotal(total *float64) {
	l.Total = total
	l.require(listUserGrantsOffsetPaginatedResponseContentFieldTotal)
}

// SetGrants sets the Grants field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (l *ListUserGrantsOffsetPaginatedResponseContent) SetGrants(grants []*UserGrant) {
	l.Grants = grants
	l.require(listUserGrantsOffsetPaginatedResponseContentFieldGrants)
}

func (l *ListUserGrantsOffsetPaginatedResponseContent) UnmarshalJSON(data []byte) error {
	type unmarshaler ListUserGrantsOffsetPaginatedResponseContent
	var value unmarshaler
	if err := json.Unmarshal(data, &value); err != nil {
		return err
	}
	*l = ListUserGrantsOffsetPaginatedResponseContent(value)
	extraProperties, err := internal.ExtractExtraProperties(data, *l)
	if err != nil {
		return err
	}
	l.extraProperties = extraProperties
	l.rawJSON = json.RawMessage(data)
	return nil
}

func (l *ListUserGrantsOffsetPaginatedResponseContent) MarshalJSON() ([]byte, error) {
	type embed ListUserGrantsOffsetPaginatedResponseContent
	var marshaler = struct {
		embed
	}{
		embed: embed(*l),
	}
	explicitMarshaler := internal.HandleExplicitFields(marshaler, l.explicitFields)
	return json.Marshal(explicitMarshaler)
}

func (l *ListUserGrantsOffsetPaginatedResponseContent) String() string {
	if len(l.rawJSON) > 0 {
		if value, err := internal.StringifyJSON(l.rawJSON); err == nil {
			return value
		}
	}
	if value, err := internal.StringifyJSON(l); err == nil {
		return value
	}
	return fmt.Sprintf("%#v", l)
}

var (
	userGrantFieldID       = big.NewInt(1 << 0)
	userGrantFieldClientID = big.NewInt(1 << 1)
	userGrantFieldUserID   = big.NewInt(1 << 2)
	userGrantFieldAudience = big.NewInt(1 << 3)
	userGrantFieldScope    = big.NewInt(1 << 4)
)

type UserGrant struct {
	// ID of the grant.
	ID *string `json:"id,omitempty" url:"id,omitempty"`
	// ID of the client.
	ClientID *string `json:"clientID,omitempty" url:"clientID,omitempty"`
	// ID of the user.
	UserID *string `json:"user_id,omitempty" url:"user_id,omitempty"`
	// Audience of the grant.
	Audience *string `json:"audience,omitempty" url:"audience,omitempty"`
	// Scopes included in this grant.
	Scope []string `json:"scope,omitempty" url:"scope,omitempty"`

	// Private bitmask of fields set to an explicit value and therefore not to be omitted
	explicitFields *big.Int `json:"-" url:"-"`

	extraProperties map[string]interface{}
	rawJSON         json.RawMessage
}

func (u *UserGrant) GetID() string {
	if u == nil || u.ID == nil {
		return ""
	}
	return *u.ID
}

func (u *UserGrant) GetClientID() string {
	if u == nil || u.ClientID == nil {
		return ""
	}
	return *u.ClientID
}

func (u *UserGrant) GetUserID() string {
	if u == nil || u.UserID == nil {
		return ""
	}
	return *u.UserID
}

func (u *UserGrant) GetAudience() string {
	if u == nil || u.Audience == nil {
		return ""
	}
	return *u.Audience
}

func (u *UserGrant) GetScope() []string {
	if u == nil || u.Scope == nil {
		return nil
	}
	return u.Scope
}

func (u *UserGrant) GetExtraProperties() map[string]interface{} {
	return u.extraProperties
}

func (u *UserGrant) require(field *big.Int) {
	if u.explicitFields == nil {
		u.explicitFields = big.NewInt(0)
	}
	u.explicitFields.Or(u.explicitFields, field)
}

// SetID sets the ID field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (u *UserGrant) SetID(id *string) {
	u.ID = id
	u.require(userGrantFieldID)
}

// SetClientID sets the ClientID field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (u *UserGrant) SetClientID(clientID *string) {
	u.ClientID = clientID
	u.require(userGrantFieldClientID)
}

// SetUserID sets the UserID field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (u *UserGrant) SetUserID(userID *string) {
	u.UserID = userID
	u.require(userGrantFieldUserID)
}

// SetAudience sets the Audience field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (u *UserGrant) SetAudience(audience *string) {
	u.Audience = audience
	u.require(userGrantFieldAudience)
}

// SetScope sets the Scope field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (u *UserGrant) SetScope(scope []string) {
	u.Scope = scope
	u.require(userGrantFieldScope)
}

func (u *UserGrant) UnmarshalJSON(data []byte) error {
	type unmarshaler UserGrant
	var value unmarshaler
	if err := json.Unmarshal(data, &value); err != nil {
		return err
	}
	*u = UserGrant(value)
	extraProperties, err := internal.ExtractExtraProperties(data, *u)
	if err != nil {
		return err
	}
	u.extraProperties = extraProperties
	u.rawJSON = json.RawMessage(data)
	return nil
}

func (u *UserGrant) MarshalJSON() ([]byte, error) {
	type embed UserGrant
	var marshaler = struct {
		embed
	}{
		embed: embed(*u),
	}
	explicitMarshaler := internal.HandleExplicitFields(marshaler, u.explicitFields)
	return json.Marshal(explicitMarshaler)
}

func (u *UserGrant) String() string {
	if len(u.rawJSON) > 0 {
		if value, err := internal.StringifyJSON(u.rawJSON); err == nil {
			return value
		}
	}
	if value, err := internal.StringifyJSON(u); err == nil {
		return value
	}
	return fmt.Sprintf("%#v", u)
}
