package ops

import (
	"path/filepath"

	"ops-assistant/internal/core/runbook"

	"gorm.io/driver/sqlite"
	"gorm.io/gorm"
)

// RunOnce executes a runbook directly without bot/channel.
func RunOnce(dbPath, baseDir, commandText, runbookName string, operator int64, inputs map[string]string) (uint, string, error) {
	db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{})
	if err != nil {
		return 0, "", err
	}
	exec := runbook.NewExecutor(db, filepath.Join(baseDir, "runbooks"))
	return exec.RunWithInputsAndMeta(commandText, runbookName, operator, inputs, runbook.NewMeta())
}
