package pgtype

import 
EnumType represents a enum type. While it implements Value, this is only in service of its type conversion duties when registered as a data type in a ConnType. It should not be used directly as a Value.
type EnumType struct {
	value  string
	status Status

	typeName   string            // PostgreSQL type name
	members    []string          // enum members
	membersMap map[string]string // map to quickly lookup member and reuse string instead of allocating
}
NewEnumType initializes a new EnumType. It retains a read-only reference to members. members must not be changed.
func ( string,  []string) *EnumType {
	 := &EnumType{typeName: , members: }
	.membersMap = make(map[string]string, len())
	for ,  := range  {
		.membersMap[] = 
	}
	return 
}

func ( *EnumType) () Value {
	return &EnumType{
		value:  .value,
		status: .status,

		typeName:   .typeName,
		members:    .members,
		membersMap: .membersMap,
	}
}

func ( *EnumType) () string {
	return .typeName
}

func ( *EnumType) () []string {
	return .members
}
Set assigns src to dst. Set purposely does not check that src is a member. This allows continued error free operation in the event the PostgreSQL enum type is modified during a connection.
func ( *EnumType) ( interface{}) error {
	if  == nil {
		.status = Null
		return nil
	}

	if ,  := .(interface{ () interface{} });  {
		 := .()
		if  !=  {
			return .()
		}
	}

	switch value := .(type) {
	case string:
		.value = 
		.status = Present
	case *string:
		if  == nil {
			.status = Null
		} else {
			.value = *
			.status = Present
		}
	case []byte:
		if  == nil {
			.status = Null
		} else {
			.value = string()
			.status = Present
		}
	default:
		if ,  := underlyingStringType();  {
			return .()
		}
		return fmt.Errorf("cannot convert %v to enum %s", , .typeName)
	}

	return nil
}

func ( EnumType) () interface{} {
	switch .status {
	case Present:
		return .value
	case Null:
		return nil
	default:
		return .status
	}
}

func ( *EnumType) ( interface{}) error {
	switch .status {
	case Present:
		switch v := .(type) {
		case *string:
			* = .value
			return nil
		case *[]byte:
			* = make([]byte, len(.value))
			copy(*, .value)
			return nil
		default:
			if ,  := GetAssignToDstType();  {
				return .()
			}
			return fmt.Errorf("unable to assign to %T", )
		}
	case Null:
		return NullAssignTo()
	}

	return fmt.Errorf("cannot decode %#v into %T", , )
}

func (EnumType) () int16 {
	return TextFormatCode
}

func ( *EnumType) ( *ConnInfo,  []byte) error {
	if  == nil {
		.status = Null
		return nil
	}
Lookup the string in membersMap to avoid an allocation.
	if ,  := .membersMap[string()];  {
		.value = 
If an enum type is modified after the initial connection it is possible to receive an unexpected value. Gracefully handle this situation. Purposely NOT modifying members and membersMap to allow for sharing members and membersMap between connections.
		.value = string()
	}
	.status = Present

	return nil
}

func ( *EnumType) ( *ConnInfo,  []byte) error {
	return .DecodeText(, )
}

func (EnumType) () int16 {
	return TextFormatCode
}

func ( EnumType) ( *ConnInfo,  []byte) ([]byte, error) {
	switch .status {
	case Null:
		return nil, nil
	case Undefined:
		return nil, errUndefined
	}

	return append(, .value...), nil
}

func ( EnumType) ( *ConnInfo,  []byte) ([]byte, error) {
	return .EncodeText(, )