// Code generated by "go-enum -type=Role"; DO NOT EDIT.

// Install go-enum by `go get -u github.com/searKing/golang/tools/go-enum`
package role

import (
	"database/sql"
	"database/sql/driver"
	"encoding"
	"encoding/json"
	"fmt"
	"strconv"
)

func _() {
	// An "invalid array index" compiler error signifies that the constant values have changed.
	// Re-run the stringer command to generate them again.
	var x [1]struct{}
	_ = x[User-1]
	_ = x[Assistant-2]
}

const _Role_name = "UserAssistant"

var _Role_index = [...]uint8{0, 4, 13}

func _() {
	var _nil_Role_value = func() (val Role) { return }()

	// An "cannot convert Role literal (type Role) to type fmt.Stringer" compiler error signifies that the base type have changed.
	// Re-run the go-enum command to generate them again.
	var _ fmt.Stringer = _nil_Role_value
}

func (i Role) String() string {
	i -= 1
	if i >= Role(len(_Role_index)-1) {
		return "Role(" + strconv.FormatInt(int64(i+1), 10) + ")"
	}
	return _Role_name[_Role_index[i]:_Role_index[i+1]]
}

// New returns a pointer to a new addr filled with the Role value passed in.
func (i Role) New() *Role {
	clone := i
	return &clone
}

var _Role_values = []Role{1, 2}

var _Role_name_to_values = map[string]Role{
	_Role_name[0:4]:  1,
	_Role_name[4:13]: 2,
}

// ParseRoleString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func ParseRoleString(s string) (Role, error) {
	if val, ok := _Role_name_to_values[s]; ok {
		return val, nil
	}
	return 0, fmt.Errorf("%s does not belong to Role values", s)
}

// RoleValues returns all values of the enum
func RoleValues() []Role {
	return _Role_values
}

// IsARole returns "true" if the value is listed in the enum definition. "false" otherwise
func (i Role) Registered() bool {
	for _, v := range _Role_values {
		if i == v {
			return true
		}
	}
	return false
}

func _() {
	var _nil_Role_value = func() (val Role) { return }()

	// An "cannot convert Role literal (type Role) to type encoding.BinaryMarshaler" compiler error signifies that the base type have changed.
	// Re-run the go-enum command to generate them again.
	var _ encoding.BinaryMarshaler = &_nil_Role_value

	// An "cannot convert Role literal (type Role) to type encoding.BinaryUnmarshaler" compiler error signifies that the base type have changed.
	// Re-run the go-enum command to generate them again.
	var _ encoding.BinaryUnmarshaler = &_nil_Role_value
}

// MarshalBinary implements the encoding.BinaryMarshaler interface for Role
func (i Role) MarshalBinary() (data []byte, err error) {
	return []byte(i.String()), nil
}

// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface for Role
func (i *Role) UnmarshalBinary(data []byte) error {
	var err error
	*i, err = ParseRoleString(string(data))
	return err
}

func _() {
	var _nil_Role_value = func() (val Role) { return }()

	// An "cannot convert Role literal (type Role) to type json.Marshaler" compiler error signifies that the base type have changed.
	// Re-run the go-enum command to generate them again.
	var _ json.Marshaler = _nil_Role_value

	// An "cannot convert Role literal (type Role) to type encoding.Unmarshaler" compiler error signifies that the base type have changed.
	// Re-run the go-enum command to generate them again.
	var _ json.Unmarshaler = &_nil_Role_value
}

// MarshalJSON implements the json.Marshaler interface for Role
func (i Role) MarshalJSON() ([]byte, error) {
	return json.Marshal(i.String())
}

// UnmarshalJSON implements the json.Unmarshaler interface for Role
func (i *Role) UnmarshalJSON(data []byte) error {
	var s string
	if err := json.Unmarshal(data, &s); err != nil {
		return fmt.Errorf("Role should be a string, got %s", data)
	}

	var err error
	*i, err = ParseRoleString(s)
	return err
}

func _() {
	var _nil_Role_value = func() (val Role) { return }()

	// An "cannot convert Role literal (type Role) to type encoding.TextMarshaler" compiler error signifies that the base type have changed.
	// Re-run the go-enum command to generate them again.
	var _ encoding.TextMarshaler = _nil_Role_value

	// An "cannot convert Role literal (type Role) to type encoding.TextUnmarshaler" compiler error signifies that the base type have changed.
	// Re-run the go-enum command to generate them again.
	var _ encoding.TextUnmarshaler = &_nil_Role_value
}

// MarshalText implements the encoding.TextMarshaler interface for Role
func (i Role) MarshalText() ([]byte, error) {
	return []byte(i.String()), nil
}

// UnmarshalText implements the encoding.TextUnmarshaler interface for Role
func (i *Role) UnmarshalText(text []byte) error {
	var err error
	*i, err = ParseRoleString(string(text))
	return err
}

//func _() {
//	var _nil_Role_value = func() (val Role) { return }()
//
//	// An "cannot convert Role literal (type Role) to type yaml.Marshaler" compiler error signifies that the base type have changed.
//	// Re-run the go-enum command to generate them again.
//	var _ yaml.Marshaler = _nil_Role_value
//
//	// An "cannot convert Role literal (type Role) to type yaml.Unmarshaler" compiler error signifies that the base type have changed.
//	// Re-run the go-enum command to generate them again.
//	var _ yaml.Unmarshaler = &_nil_Role_value
//}

// MarshalYAML implements a YAML Marshaler for Role
func (i Role) MarshalYAML() (interface{}, error) {
	return i.String(), nil
}

// UnmarshalYAML implements a YAML Unmarshaler for Role
func (i *Role) UnmarshalYAML(unmarshal func(interface{}) error) error {
	var s string
	if err := unmarshal(&s); err != nil {
		return err
	}

	var err error
	*i, err = ParseRoleString(s)
	return err
}

func _() {
	var _nil_Role_value = func() (val Role) { return }()

	// An "cannot convert Role literal (type Role) to type driver.Valuer" compiler error signifies that the base type have changed.
	// Re-run the go-enum command to generate them again.
	var _ driver.Valuer = _nil_Role_value

	// An "cannot convert Role literal (type Role) to type sql.Scanner" compiler error signifies that the base type have changed.
	// Re-run the go-enum command to generate them again.
	var _ sql.Scanner = &_nil_Role_value
}

func (i Role) Value() (driver.Value, error) {
	return i.String(), nil
}

func (i *Role) Scan(value interface{}) error {
	if value == nil {
		return nil
	}

	str, ok := value.(string)
	if !ok {
		bytes, ok := value.([]byte)
		if !ok {
			return fmt.Errorf("value is not a byte slice")
		}

		str = string(bytes[:])
	}

	val, err := ParseRoleString(str)
	if err != nil {
		return err
	}

	*i = val
	return nil
}

// RoleSliceContains reports whether sunEnums is within enums.
func RoleSliceContains(enums []Role, sunEnums ...Role) bool {
	var seenEnums = map[Role]bool{}
	for _, e := range sunEnums {
		seenEnums[e] = false
	}

	for _, v := range enums {
		if _, has := seenEnums[v]; has {
			seenEnums[v] = true
		}
	}

	for _, seen := range seenEnums {
		if !seen {
			return false
		}
	}

	return true
}

// RoleSliceContainsAny reports whether any sunEnum is within enums.
func RoleSliceContainsAny(enums []Role, sunEnums ...Role) bool {
	var seenEnums = map[Role]struct{}{}
	for _, e := range sunEnums {
		seenEnums[e] = struct{}{}
	}

	for _, v := range enums {
		if _, has := seenEnums[v]; has {
			return true
		}
	}

	return false
}
