/*
 * In-Memory DB API
 *
 * API description for the IONOS In-Memory DB
 *
 * API version: 1.0.0
 * Contact: support@cloud.ionos.com
 */

// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.

package ionoscloud

import (
	"encoding/json"
	"fmt"
)

// EvictionPolicy The eviction policy for the replica set. The default value is `allkeys-lru`. | Policy                | Description | |-----------------------|-------------| | **noeviction**        | No eviction policy is used. In-Memory DB will never remove any data. If the memory limit is reached, an error will be returned on write operations. | | **allkeys-lru**       | The least recently used keys will be removed first. | | **allkeys-lfu**       | The least frequently used keys will be removed first. | | **allkeys-random**    | Random keys will be removed. | | **volatile-lru**      | The least recently used keys will be removed first, but only among keys with the `expire` field set to `true`. | | **volatile-lfu**      | The least frequently used keys will be removed first, but only among keys with the `expire` field set to `true`. | | **volatile-random**   | Random keys will be removed, but only among keys with the `expire` field set to `true`. | | **volatile-ttl**      | The key with the nearest time to live will be removed first, but only among keys with the `expire` field set to `true`. |
type EvictionPolicy string

// List of EvictionPolicy
const (
	EVICTIONPOLICY_NOEVICTION      EvictionPolicy = "noeviction"
	EVICTIONPOLICY_ALLKEYS_LRU     EvictionPolicy = "allkeys-lru"
	EVICTIONPOLICY_ALLKEYS_LFU     EvictionPolicy = "allkeys-lfu"
	EVICTIONPOLICY_ALLKEYS_RANDOM  EvictionPolicy = "allkeys-random"
	EVICTIONPOLICY_VOLATILE_LRU    EvictionPolicy = "volatile-lru"
	EVICTIONPOLICY_VOLATILE_LFU    EvictionPolicy = "volatile-lfu"
	EVICTIONPOLICY_VOLATILE_RANDOM EvictionPolicy = "volatile-random"
	EVICTIONPOLICY_VOLATILE_TTL    EvictionPolicy = "volatile-ttl"
)

func (v *EvictionPolicy) UnmarshalJSON(src []byte) error {
	var value string
	err := json.Unmarshal(src, &value)
	if err != nil {
		return err
	}
	enumTypeValue := EvictionPolicy(value)
	for _, existing := range []EvictionPolicy{"noeviction", "allkeys-lru", "allkeys-lfu", "allkeys-random", "volatile-lru", "volatile-lfu", "volatile-random", "volatile-ttl"} {
		if existing == enumTypeValue {
			*v = enumTypeValue
			return nil
		}
	}

	return fmt.Errorf("%+v is not a valid EvictionPolicy", value)
}

// Ptr returns reference to EvictionPolicy value
func (v EvictionPolicy) Ptr() *EvictionPolicy {
	return &v
}

type NullableEvictionPolicy struct {
	value *EvictionPolicy
	isSet bool
}

func (v NullableEvictionPolicy) Get() *EvictionPolicy {
	return v.value
}

func (v *NullableEvictionPolicy) Set(val *EvictionPolicy) {
	v.value = val
	v.isSet = true
}

func (v NullableEvictionPolicy) IsSet() bool {
	return v.isSet
}

func (v *NullableEvictionPolicy) Unset() {
	v.value = nil
	v.isSet = false
}

func NewNullableEvictionPolicy(val *EvictionPolicy) *NullableEvictionPolicy {
	return &NullableEvictionPolicy{value: val, isSet: true}
}

func (v NullableEvictionPolicy) MarshalJSON() ([]byte, error) {
	return json.Marshal(v.value)
}

func (v *NullableEvictionPolicy) UnmarshalJSON(src []byte) error {
	v.isSet = true
	return json.Unmarshal(src, &v.value)
}
