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

type RulesConfig struct {
	// Key for a rules config variable.
	Key *string `json:"key,omitempty" url:"key,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 (r *RulesConfig) GetKey() string {
	if r == nil || r.Key == nil {
		return ""
	}
	return *r.Key
}

func (r *RulesConfig) GetExtraProperties() map[string]interface{} {
	return r.ExtraProperties
}

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

// SetKey sets the Key field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (r *RulesConfig) SetKey(key *string) {
	r.Key = key
	r.require(rulesConfigFieldKey)
}

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

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

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

var (
	setRulesConfigResponseContentFieldKey   = big.NewInt(1 << 0)
	setRulesConfigResponseContentFieldValue = big.NewInt(1 << 1)
)

type SetRulesConfigResponseContent struct {
	// Key for a rules config variable.
	Key string `json:"key" url:"key"`
	// Value for a rules config variable.
	Value string `json:"value" url:"value"`

	// 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 (s *SetRulesConfigResponseContent) GetKey() string {
	if s == nil {
		return ""
	}
	return s.Key
}

func (s *SetRulesConfigResponseContent) GetValue() string {
	if s == nil {
		return ""
	}
	return s.Value
}

func (s *SetRulesConfigResponseContent) GetExtraProperties() map[string]interface{} {
	return s.ExtraProperties
}

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

// SetKey sets the Key field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (s *SetRulesConfigResponseContent) SetKey(key string) {
	s.Key = key
	s.require(setRulesConfigResponseContentFieldKey)
}

// SetValue sets the Value field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (s *SetRulesConfigResponseContent) SetValue(value string) {
	s.Value = value
	s.require(setRulesConfigResponseContentFieldValue)
}

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

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

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