// Code generated by go-enum DO NOT EDIT.
// Version:
// Revision:
// Build Date:
// Built By:

package plan

import (
	"fmt"
	"strings"

	"github.com/pkg/errors"
)

const (
	// SSD is a DiskType of type SSD.
	SSD DiskType = iota
	// HDD is a DiskType of type HDD.
	HDD
)

var ErrInvalidDiskType = errors.New("not a valid DiskType")

const _DiskTypeName = "SSDHDD"

var _DiskTypeMap = map[DiskType]string{
	SSD: _DiskTypeName[0:3],
	HDD: _DiskTypeName[3:6],
}

// String implements the Stringer interface.
func (x DiskType) String() string {
	if str, ok := _DiskTypeMap[x]; ok {
		return str
	}
	return fmt.Sprintf("DiskType(%d)", x)
}

var _DiskTypeValue = map[string]DiskType{
	_DiskTypeName[0:3]:                  SSD,
	strings.ToLower(_DiskTypeName[0:3]): SSD,
	_DiskTypeName[3:6]:                  HDD,
	strings.ToLower(_DiskTypeName[3:6]): HDD,
}

// ParseDiskType attempts to convert a string to a DiskType.
func ParseDiskType(name string) (DiskType, error) {
	if x, ok := _DiskTypeValue[name]; ok {
		return x, nil
	}
	// Case insensitive parse, do a separate lookup to prevent unnecessary cost of lowercasing a string if we don't need to.
	if x, ok := _DiskTypeValue[strings.ToLower(name)]; ok {
		return x, nil
	}
	return DiskType(0), fmt.Errorf("%s is %w", name, ErrInvalidDiskType)
}

// MarshalText implements the text marshaller method.
func (x DiskType) MarshalText() ([]byte, error) {
	return []byte(x.String()), nil
}

// UnmarshalText implements the text unmarshaller method.
func (x *DiskType) UnmarshalText(text []byte) error {
	name := string(text)
	tmp, err := ParseDiskType(name)
	if err != nil {
		return err
	}
	*x = tmp
	return nil
}
