package template

import "errors"

type StringOrSlice []string

func (s *StringOrSlice) UnmarshalYAML(unmarshal func(any) error) error {
	var single string
	if err := unmarshal(&single); err == nil {
		if single == "" {
			*s = nil
			return nil
		}
		*s = []string{single}
		return nil
	}

	var multi []string
	if err := unmarshal(&multi); err == nil {
		*s = multi
		return nil
	}

	var nothing *struct{}
	if err := unmarshal(&nothing); err == nil {
		*s = nil
		return nil
	}

	return errors.New("expected string, []string, or null")
}
