package logs

import (
	
	
	
)

var _ slog.LogValuer = sliceGroup{}

// sliceGroup is a slice that implements [slog.LogValuer]. Each element is
// logged as an attribute within a group, with numeric keys "0", "1", and so on.
type sliceGroup []slog.Value

// LogValue returns a group value whose attributes are the elements of l,
// keyed by their index.
func ( sliceGroup) () slog.Value {
	 := make([]slog.Attr, len())
	for ,  := range  {
		[] = slog.Attr{
			Key:   strconv.Itoa(),
			Value: ,
		}
	}
	return slog.GroupValue(...)
}

// SliceGroupValue returns an [slog.Value] that logs values as a group with
// numeric keys "0", "1", and so on.
func ( ...slog.Value) slog.Value {
	return slog.AnyValue(sliceGroup())
}

// SliceGroup returns an [slog.Attr] that logs values as a group with numeric keys
// "0", "1", and so on.
func ( string,  ...slog.Value) slog.Attr {
	return slog.Attr{
		Key:   ,
		Value: SliceGroupValue(...),
	}
}

// typedError wraps an error as a group with attributes "type" (the type
// string from reflection) and "value" (the error itself).
type typedError struct {
	Error error
}

// LogValue returns a group with "type" and "value" attributes
// for e.Error: the type string from reflection, and the error itself.
func ( typedError) () slog.Value {
	 := reflect.TypeOf(.Error)
	if  == nil {
		return slog.Value{}
	}
	return slog.GroupValue(
		slog.String("type", .String()),
		slog.Any("value", .Error),
	)
}

// Error returns an [slog.Attr] with key "error" for the given error. The
// value is a group with "type" (the error’s type string from reflection) and
// "value" (the error itself).
func ( error) slog.Attr {
	return NamedError("error", )
}

// NamedError returns an [slog.Attr] with the given key for the error. The
// value is a group with "type" (the error’s type string from reflection) and
// "value" (the error itself).
func ( string,  error) slog.Attr {
	return slog.Any(, typedError{})
}