package app

import "time"

type FaultSeverity int

const (
	FaultSeverityWarn FaultSeverity = iota
	FaultSeverityDegraded
	FaultSeverityMuted
	FaultSeverityFaulted
)

var faultSeverityNames = []string{"warn", "degraded", "muted", "faulted"}

func (s FaultSeverity) String() string {
	if int(s) < 0 || int(s) >= len(faultSeverityNames) {
		return "unknown"
	}
	return faultSeverityNames[s]
}

// MarshalText implements encoding.TextMarshaler so that FaultSeverity
// renders as a human-friendly string in JSON and other text contexts.
func (s FaultSeverity) MarshalText() ([]byte, error) {
	return []byte(s.String()), nil
}

type FaultReason string

const (
	FaultReasonUnknown       FaultReason = "unknown"
	FaultReasonQueueCritical FaultReason = "queueCritical"
	FaultReasonLateBuffers   FaultReason = "lateBuffers"
	FaultReasonWriteTimeout  FaultReason = "writeTimeout"
	FaultReasonQueueEmpty    FaultReason = "queueEmpty"
)

// FaultEvent captures a single fault observation along with its severity and
// optional human-readable hint. Fault history and last-fault exposure rely on
// this struct so operators can reason about runtime behavior.
type FaultEvent struct {
	Time     time.Time     `json:"time"`
	Reason   FaultReason   `json:"reason"`
	Severity FaultSeverity `json:"severity"`
	Message  string        `json:"message,omitempty"`
}
