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

type CreatePublicKeyDeviceCredentialResponseContent struct {
	// The credential's identifier
	ID string `json:"id" url:"id"`

	// 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 (c *CreatePublicKeyDeviceCredentialResponseContent) GetID() string {
	if c == nil {
		return ""
	}
	return c.ID
}

func (c *CreatePublicKeyDeviceCredentialResponseContent) GetExtraProperties() map[string]interface{} {
	return c.ExtraProperties
}

func (c *CreatePublicKeyDeviceCredentialResponseContent) require(field *big.Int) {
	if c.explicitFields == nil {
		c.explicitFields = big.NewInt(0)
	}
	c.explicitFields.Or(c.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 (c *CreatePublicKeyDeviceCredentialResponseContent) SetID(id string) {
	c.ID = id
	c.require(createPublicKeyDeviceCredentialResponseContentFieldID)
}

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

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

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

var (
	deviceCredentialFieldID         = big.NewInt(1 << 0)
	deviceCredentialFieldDeviceName = big.NewInt(1 << 1)
	deviceCredentialFieldDeviceID   = big.NewInt(1 << 2)
	deviceCredentialFieldType       = big.NewInt(1 << 3)
	deviceCredentialFieldUserID     = big.NewInt(1 << 4)
	deviceCredentialFieldClientID   = big.NewInt(1 << 5)
)

type DeviceCredential struct {
	// ID of this device.
	ID *string `json:"id,omitempty" url:"id,omitempty"`
	// User agent for this device
	DeviceName *string `json:"device_name,omitempty" url:"device_name,omitempty"`
	// Unique identifier for the device. NOTE: This field is generally not populated for refresh_tokens and rotating_refresh_tokens
	DeviceID *string                   `json:"device_id,omitempty" url:"device_id,omitempty"`
	Type     *DeviceCredentialTypeEnum `json:"type,omitempty" url:"type,omitempty"`
	// user_id this credential is associated with.
	UserID *string `json:"user_id,omitempty" url:"user_id,omitempty"`
	// client_id of the client (application) this credential is for.
	ClientID *string `json:"client_id,omitempty" url:"client_id,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 (d *DeviceCredential) GetID() string {
	if d == nil || d.ID == nil {
		return ""
	}
	return *d.ID
}

func (d *DeviceCredential) GetDeviceName() string {
	if d == nil || d.DeviceName == nil {
		return ""
	}
	return *d.DeviceName
}

func (d *DeviceCredential) GetDeviceID() string {
	if d == nil || d.DeviceID == nil {
		return ""
	}
	return *d.DeviceID
}

func (d *DeviceCredential) GetType() DeviceCredentialTypeEnum {
	if d == nil || d.Type == nil {
		return ""
	}
	return *d.Type
}

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

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

func (d *DeviceCredential) GetExtraProperties() map[string]interface{} {
	return d.extraProperties
}

func (d *DeviceCredential) require(field *big.Int) {
	if d.explicitFields == nil {
		d.explicitFields = big.NewInt(0)
	}
	d.explicitFields.Or(d.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 (d *DeviceCredential) SetID(id *string) {
	d.ID = id
	d.require(deviceCredentialFieldID)
}

// SetDeviceName sets the DeviceName field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (d *DeviceCredential) SetDeviceName(deviceName *string) {
	d.DeviceName = deviceName
	d.require(deviceCredentialFieldDeviceName)
}

// SetDeviceID sets the DeviceID field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (d *DeviceCredential) SetDeviceID(deviceID *string) {
	d.DeviceID = deviceID
	d.require(deviceCredentialFieldDeviceID)
}

// SetType sets the Type field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (d *DeviceCredential) SetType(type_ *DeviceCredentialTypeEnum) {
	d.Type = type_
	d.require(deviceCredentialFieldType)
}

// 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 (d *DeviceCredential) SetUserID(userID *string) {
	d.UserID = userID
	d.require(deviceCredentialFieldUserID)
}

// 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 (d *DeviceCredential) SetClientID(clientID *string) {
	d.ClientID = clientID
	d.require(deviceCredentialFieldClientID)
}

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

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

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

// Type of credential. Must be `public_key`.
type DeviceCredentialPublicKeyTypeEnum = string

// Type of credentials to retrieve. Must be `public_key`, `refresh_token` or `rotating_refresh_token`. The property will default to `refresh_token` when paging is requested
type DeviceCredentialTypeEnum string

const (
	DeviceCredentialTypeEnumPublicKey            DeviceCredentialTypeEnum = "public_key"
	DeviceCredentialTypeEnumRefreshToken         DeviceCredentialTypeEnum = "refresh_token"
	DeviceCredentialTypeEnumRotatingRefreshToken DeviceCredentialTypeEnum = "rotating_refresh_token"
)

func NewDeviceCredentialTypeEnumFromString(s string) (DeviceCredentialTypeEnum, error) {
	switch s {
	case "public_key":
		return DeviceCredentialTypeEnumPublicKey, nil
	case "refresh_token":
		return DeviceCredentialTypeEnumRefreshToken, nil
	case "rotating_refresh_token":
		return DeviceCredentialTypeEnumRotatingRefreshToken, nil
	}
	var t DeviceCredentialTypeEnum
	return "", fmt.Errorf("%s is not a valid %T", s, t)
}

func (d DeviceCredentialTypeEnum) Ptr() *DeviceCredentialTypeEnum {
	return &d
}

var (
	listDeviceCredentialsOffsetPaginatedResponseContentFieldStart             = big.NewInt(1 << 0)
	listDeviceCredentialsOffsetPaginatedResponseContentFieldLimit             = big.NewInt(1 << 1)
	listDeviceCredentialsOffsetPaginatedResponseContentFieldTotal             = big.NewInt(1 << 2)
	listDeviceCredentialsOffsetPaginatedResponseContentFieldDeviceCredentials = big.NewInt(1 << 3)
)

type ListDeviceCredentialsOffsetPaginatedResponseContent 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"`
	DeviceCredentials []*DeviceCredential `json:"device_credentials,omitempty" url:"device_credentials,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 *ListDeviceCredentialsOffsetPaginatedResponseContent) GetStart() float64 {
	if l == nil || l.Start == nil {
		return 0
	}
	return *l.Start
}

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

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

func (l *ListDeviceCredentialsOffsetPaginatedResponseContent) GetDeviceCredentials() []*DeviceCredential {
	if l == nil || l.DeviceCredentials == nil {
		return nil
	}
	return l.DeviceCredentials
}

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

func (l *ListDeviceCredentialsOffsetPaginatedResponseContent) 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 *ListDeviceCredentialsOffsetPaginatedResponseContent) SetStart(start *float64) {
	l.Start = start
	l.require(listDeviceCredentialsOffsetPaginatedResponseContentFieldStart)
}

// 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 *ListDeviceCredentialsOffsetPaginatedResponseContent) SetLimit(limit *float64) {
	l.Limit = limit
	l.require(listDeviceCredentialsOffsetPaginatedResponseContentFieldLimit)
}

// 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 *ListDeviceCredentialsOffsetPaginatedResponseContent) SetTotal(total *float64) {
	l.Total = total
	l.require(listDeviceCredentialsOffsetPaginatedResponseContentFieldTotal)
}

// SetDeviceCredentials sets the DeviceCredentials field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (l *ListDeviceCredentialsOffsetPaginatedResponseContent) SetDeviceCredentials(deviceCredentials []*DeviceCredential) {
	l.DeviceCredentials = deviceCredentials
	l.require(listDeviceCredentialsOffsetPaginatedResponseContentFieldDeviceCredentials)
}

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

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

func (l *ListDeviceCredentialsOffsetPaginatedResponseContent) 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)
}
