package util

import "strings"

func NormalizeAvatarURL(raw string) string {
	raw = strings.TrimSpace(raw)
	if raw == "" {
		return ""
	}
	if strings.HasPrefix(raw, "//") {
		return "https:" + raw
	}
	return raw
}

func PickAvatarFromMap(m map[string]interface{}) string {
	if m == nil {
		return ""
	}
	for _, key := range []string{"avatar", "avatarUrl", "avatar_url", "profileImage"} {
		if av, ok := m[key].(string); ok {
			if normalized := NormalizeAvatarURL(av); normalized != "" {
				return normalized
			}
		}
	}
	return ""
}
