// Copyright 2022 schukai GmbH
// SPDX-License-Identifier: AGPL-3.0

package configuration

import (
	"reflect"
	"strconv"
)

func getMapForProperties[C any](c C) (map[string]string, []error) {

	m := make(map[string]string)

	var errors []error

	runOnTags(c, []string{"properties"}, func(tagValue string, field reflect.Value) {

		switch field.Kind() {
		case reflect.String:
			m[tagValue] = field.String()
		case reflect.Int:
			m[tagValue] = strconv.Itoa(int(field.Int()))
		case reflect.Bool:
			if field.Bool() {
				m[tagValue] = "true"
			} else {
				m[tagValue] = "false"
			}

		default:
			errors = append(errors, newUnsupportedReflectKindError(field.Type()))
		}

	})

	return m, errors
}