//autogenerated:yes
//nolint:revive,misspell,govet,lll,dupl,gocritic
package uavionix

import (
	"fmt"
	"strconv"
	"strings"
)

// State flags for ADS-B transponder fault report
type UAVIONIX_ADSB_OUT_STATUS_FAULT uint64

const (
	UAVIONIX_ADSB_OUT_STATUS_FAULT_STATUS_MESSAGE_UNAVAIL UAVIONIX_ADSB_OUT_STATUS_FAULT = 8
	UAVIONIX_ADSB_OUT_STATUS_FAULT_GPS_NO_POS             UAVIONIX_ADSB_OUT_STATUS_FAULT = 16
	UAVIONIX_ADSB_OUT_STATUS_FAULT_GPS_UNAVAIL            UAVIONIX_ADSB_OUT_STATUS_FAULT = 32
	UAVIONIX_ADSB_OUT_STATUS_FAULT_TX_SYSTEM_FAIL         UAVIONIX_ADSB_OUT_STATUS_FAULT = 64
	UAVIONIX_ADSB_OUT_STATUS_FAULT_MAINT_REQ              UAVIONIX_ADSB_OUT_STATUS_FAULT = 128
)

var values_UAVIONIX_ADSB_OUT_STATUS_FAULT = []UAVIONIX_ADSB_OUT_STATUS_FAULT{
	UAVIONIX_ADSB_OUT_STATUS_FAULT_STATUS_MESSAGE_UNAVAIL,
	UAVIONIX_ADSB_OUT_STATUS_FAULT_GPS_NO_POS,
	UAVIONIX_ADSB_OUT_STATUS_FAULT_GPS_UNAVAIL,
	UAVIONIX_ADSB_OUT_STATUS_FAULT_TX_SYSTEM_FAIL,
	UAVIONIX_ADSB_OUT_STATUS_FAULT_MAINT_REQ,
}

var value_to_label_UAVIONIX_ADSB_OUT_STATUS_FAULT = map[UAVIONIX_ADSB_OUT_STATUS_FAULT]string{
	UAVIONIX_ADSB_OUT_STATUS_FAULT_STATUS_MESSAGE_UNAVAIL: "UAVIONIX_ADSB_OUT_STATUS_FAULT_STATUS_MESSAGE_UNAVAIL",
	UAVIONIX_ADSB_OUT_STATUS_FAULT_GPS_NO_POS:             "UAVIONIX_ADSB_OUT_STATUS_FAULT_GPS_NO_POS",
	UAVIONIX_ADSB_OUT_STATUS_FAULT_GPS_UNAVAIL:            "UAVIONIX_ADSB_OUT_STATUS_FAULT_GPS_UNAVAIL",
	UAVIONIX_ADSB_OUT_STATUS_FAULT_TX_SYSTEM_FAIL:         "UAVIONIX_ADSB_OUT_STATUS_FAULT_TX_SYSTEM_FAIL",
	UAVIONIX_ADSB_OUT_STATUS_FAULT_MAINT_REQ:              "UAVIONIX_ADSB_OUT_STATUS_FAULT_MAINT_REQ",
}

var label_to_value_UAVIONIX_ADSB_OUT_STATUS_FAULT = map[string]UAVIONIX_ADSB_OUT_STATUS_FAULT{
	"UAVIONIX_ADSB_OUT_STATUS_FAULT_STATUS_MESSAGE_UNAVAIL": UAVIONIX_ADSB_OUT_STATUS_FAULT_STATUS_MESSAGE_UNAVAIL,
	"UAVIONIX_ADSB_OUT_STATUS_FAULT_GPS_NO_POS":             UAVIONIX_ADSB_OUT_STATUS_FAULT_GPS_NO_POS,
	"UAVIONIX_ADSB_OUT_STATUS_FAULT_GPS_UNAVAIL":            UAVIONIX_ADSB_OUT_STATUS_FAULT_GPS_UNAVAIL,
	"UAVIONIX_ADSB_OUT_STATUS_FAULT_TX_SYSTEM_FAIL":         UAVIONIX_ADSB_OUT_STATUS_FAULT_TX_SYSTEM_FAIL,
	"UAVIONIX_ADSB_OUT_STATUS_FAULT_MAINT_REQ":              UAVIONIX_ADSB_OUT_STATUS_FAULT_MAINT_REQ,
}

// MarshalText implements the encoding.TextMarshaler interface.
func (e UAVIONIX_ADSB_OUT_STATUS_FAULT) MarshalText() ([]byte, error) {
	if e == 0 {
		return []byte("0"), nil
	}
	var names []string
	for _, val := range values_UAVIONIX_ADSB_OUT_STATUS_FAULT {
		if e&val == val {
			names = append(names, value_to_label_UAVIONIX_ADSB_OUT_STATUS_FAULT[val])
		}
	}
	return []byte(strings.Join(names, " | ")), nil
}

// UnmarshalText implements the encoding.TextUnmarshaler interface.
func (e *UAVIONIX_ADSB_OUT_STATUS_FAULT) UnmarshalText(text []byte) error {
	labels := strings.Split(string(text), " | ")
	var mask UAVIONIX_ADSB_OUT_STATUS_FAULT
	for _, label := range labels {
		if value, ok := label_to_value_UAVIONIX_ADSB_OUT_STATUS_FAULT[label]; ok {
			mask |= value
		} else if value, err := strconv.Atoi(label); err == nil {
			mask |= UAVIONIX_ADSB_OUT_STATUS_FAULT(value)
		} else {
			return fmt.Errorf("invalid label '%s'", label)
		}
	}
	*e = mask
	return nil
}

// String implements the fmt.Stringer interface.
func (e UAVIONIX_ADSB_OUT_STATUS_FAULT) String() string {
	val, _ := e.MarshalText()
	return string(val)
}
