package flag

import (
	"strings"

	flags "github.com/jessevdk/go-flags"
)

type HealthCheckTypeWithDeprecatedValue struct {
	Type string
}

func (HealthCheckTypeWithDeprecatedValue) Complete(prefix string) []flags.Completion {
	return completions([]string{"http", "port", "process"}, prefix, false)
}

func (h *HealthCheckTypeWithDeprecatedValue) UnmarshalFlag(val string) error {
	valLower := strings.ToLower(val)
	switch valLower {
	case "port", "process", "http", "none":
		h.Type = valLower
	default:
		return &flags.Error{
			Type:    flags.ErrRequired,
			Message: `HEALTH_CHECK_TYPE must be "port", "process", or "http"`,
		}
	}
	return nil
}
