package onstartup

import (
	"github.com/OliveTin/OliveTin/internal/acl"
	config "github.com/OliveTin/OliveTin/internal/config"
	"github.com/OliveTin/OliveTin/internal/executor"
	log "github.com/sirupsen/logrus"
)

func Execute(cfg *config.Config, ex *executor.Executor) {
	user := acl.UserFromSystem(cfg, "startup")

	for _, action := range cfg.Actions {
		if action.ExecOnStartup {
			log.WithFields(log.Fields{
				"action": action.Title,
			}).Infof("Startup action")

			req := &executor.ExecutionRequest{
				Binding:           ex.FindBindingWithNoEntity(action),
				Arguments:         nil,
				Cfg:               cfg,
				Tags:              []string{},
				AuthenticatedUser: user,
			}

			ex.ExecRequest(req)
		}
	}
}
