// 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 (
	listUserBlocksByIdentifierResponseContentFieldBlockedFor = big.NewInt(1 << 0)
)

type ListUserBlocksByIdentifierResponseContent struct {
	// Array of identifier + IP address pairs.  IP address is optional, and may be omitted in certain circumstances (such as Account Lockout mode).
	BlockedFor []*UserBlockIdentifier `json:"blocked_for,omitempty" url:"blocked_for,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 *ListUserBlocksByIdentifierResponseContent) GetBlockedFor() []*UserBlockIdentifier {
	if l == nil || l.BlockedFor == nil {
		return nil
	}
	return l.BlockedFor
}

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

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

// SetBlockedFor sets the BlockedFor field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (l *ListUserBlocksByIdentifierResponseContent) SetBlockedFor(blockedFor []*UserBlockIdentifier) {
	l.BlockedFor = blockedFor
	l.require(listUserBlocksByIdentifierResponseContentFieldBlockedFor)
}

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

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

func (l *ListUserBlocksByIdentifierResponseContent) 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 (
	listUserBlocksResponseContentFieldBlockedFor = big.NewInt(1 << 0)
)

type ListUserBlocksResponseContent struct {
	// Array of identifier + IP address pairs.  IP address is optional, and may be omitted in certain circumstances (such as Account Lockout mode).
	BlockedFor []*UserBlockIdentifier `json:"blocked_for,omitempty" url:"blocked_for,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 *ListUserBlocksResponseContent) GetBlockedFor() []*UserBlockIdentifier {
	if l == nil || l.BlockedFor == nil {
		return nil
	}
	return l.BlockedFor
}

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

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

// SetBlockedFor sets the BlockedFor field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (l *ListUserBlocksResponseContent) SetBlockedFor(blockedFor []*UserBlockIdentifier) {
	l.BlockedFor = blockedFor
	l.require(listUserBlocksResponseContentFieldBlockedFor)
}

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

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

func (l *ListUserBlocksResponseContent) 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 (
	userBlockIdentifierFieldIdentifier = big.NewInt(1 << 0)
	userBlockIdentifierFieldIP         = big.NewInt(1 << 1)
	userBlockIdentifierFieldConnection = big.NewInt(1 << 2)
)

type UserBlockIdentifier struct {
	// Identifier (should be any of an `email`, `username`, or `phone_number`)
	Identifier *string `json:"identifier,omitempty" url:"identifier,omitempty"`
	// IP Address
	IP *string `json:"ip,omitempty" url:"ip,omitempty"`
	// Connection identifier
	Connection *string `json:"connection,omitempty" url:"connection,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{} `json:"-" url:"-"`

	rawJSON json.RawMessage
}

func (u *UserBlockIdentifier) GetIdentifier() string {
	if u == nil || u.Identifier == nil {
		return ""
	}
	return *u.Identifier
}

func (u *UserBlockIdentifier) GetIP() string {
	if u == nil || u.IP == nil {
		return ""
	}
	return *u.IP
}

func (u *UserBlockIdentifier) GetConnection() string {
	if u == nil || u.Connection == nil {
		return ""
	}
	return *u.Connection
}

func (u *UserBlockIdentifier) GetExtraProperties() map[string]interface{} {
	return u.ExtraProperties
}

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

// SetIdentifier sets the Identifier field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (u *UserBlockIdentifier) SetIdentifier(identifier *string) {
	u.Identifier = identifier
	u.require(userBlockIdentifierFieldIdentifier)
}

// SetIP sets the IP field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (u *UserBlockIdentifier) SetIP(ip *string) {
	u.IP = ip
	u.require(userBlockIdentifierFieldIP)
}

// SetConnection sets the Connection field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (u *UserBlockIdentifier) SetConnection(connection *string) {
	u.Connection = connection
	u.require(userBlockIdentifierFieldConnection)
}

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

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

func (u *UserBlockIdentifier) 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)
}
