package infra

import "fmt"

// MetabaseCreateUser crea un nuevo usuario en Metabase.
// firstName, lastName y email son obligatorios.
// password es opcional: si esta vacio, Metabase envia email de invitacion.
// groupIDs es opcional: IDs de grupos a asignar (nil = solo grupo default).
func MetabaseCreateUser(client MetabaseClient, firstName, lastName, email, password string, groupIDs []int) (map[string]any, error) {
	body := map[string]any{
		"first_name": firstName,
		"last_name":  lastName,
		"email":      email,
	}
	if password != "" {
		body["password"] = password
	}
	if len(groupIDs) > 0 {
		body["group_ids"] = groupIDs
	}

	result, err := metabaseRequest("POST", client.BaseURL, client.Token, "/api/user", body)
	if err != nil {
		return nil, fmt.Errorf("metabase create user: %w", err)
	}

	return result, nil
}
