// generated by jsonenums -type=SemverPolicyType; DO NOT EDIT

package policy

import (
	"encoding/json"
	"fmt"
)

var (
	_SemverPolicyTypeNameToValue = map[string]SemverPolicyType{
		"SemverPolicyTypeNone":  SemverPolicyTypeNone,
		"SemverPolicyTypeAll":   SemverPolicyTypeAll,
		"SemverPolicyTypeMajor": SemverPolicyTypeMajor,
		"SemverPolicyTypeMinor": SemverPolicyTypeMinor,
		"SemverPolicyTypePatch": SemverPolicyTypePatch,
	}

	_SemverPolicyTypeValueToName = map[SemverPolicyType]string{
		SemverPolicyTypeNone:  "SemverPolicyTypeNone",
		SemverPolicyTypeAll:   "SemverPolicyTypeAll",
		SemverPolicyTypeMajor: "SemverPolicyTypeMajor",
		SemverPolicyTypeMinor: "SemverPolicyTypeMinor",
		SemverPolicyTypePatch: "SemverPolicyTypePatch",
	}
)

func init() {
	var v SemverPolicyType
	if _, ok := interface{}(v).(fmt.Stringer); ok {
		_SemverPolicyTypeNameToValue = map[string]SemverPolicyType{
			interface{}(SemverPolicyTypeNone).(fmt.Stringer).String():  SemverPolicyTypeNone,
			interface{}(SemverPolicyTypeAll).(fmt.Stringer).String():   SemverPolicyTypeAll,
			interface{}(SemverPolicyTypeMajor).(fmt.Stringer).String(): SemverPolicyTypeMajor,
			interface{}(SemverPolicyTypeMinor).(fmt.Stringer).String(): SemverPolicyTypeMinor,
			interface{}(SemverPolicyTypePatch).(fmt.Stringer).String(): SemverPolicyTypePatch,
		}
	}
}

// MarshalJSON is generated so SemverPolicyType satisfies json.Marshaler.
func (r SemverPolicyType) MarshalJSON() ([]byte, error) {
	if s, ok := interface{}(r).(fmt.Stringer); ok {
		return json.Marshal(s.String())
	}
	s, ok := _SemverPolicyTypeValueToName[r]
	if !ok {
		return nil, fmt.Errorf("invalid SemverPolicyType: %d", r)
	}
	return json.Marshal(s)
}

// UnmarshalJSON is generated so SemverPolicyType satisfies json.Unmarshaler.
func (r *SemverPolicyType) UnmarshalJSON(data []byte) error {
	var s string
	if err := json.Unmarshal(data, &s); err != nil {
		return fmt.Errorf("SemverPolicyType should be a string, got %s", data)
	}
	v, ok := _SemverPolicyTypeNameToValue[s]
	if !ok {
		return fmt.Errorf("invalid SemverPolicyType %q", s)
	}
	*r = v
	return nil
}
