package admin

import "strings"

func buildWebSearchProviderSecretsStatus(policy map[string]any) map[string]any {
	searchSection, ok := policy["search"].(map[string]any)
	if !ok {
		return nil
	}
	webSearch, ok := searchSection["web_search"].(map[string]any)
	if !ok {
		return nil
	}
	providers, ok := webSearch["providers"].([]any)
	if !ok {
		return nil
	}
	out := map[string]any{}
	for _, item := range providers {
		pm, ok := item.(map[string]any)
		if !ok {
			continue
		}
		id, _ := pm["id"].(string)
		if strings.TrimSpace(id) == "" {
			continue
		}
		apiKey, _ := pm["api_key"].(string)
		out[id] = map[string]any{
			"configured": strings.TrimSpace(apiKey) != "",
		}
	}
	if len(out) == 0 {
		return nil
	}
	return out
}
