package services

import (
	"nadir/internal/rbac"

	"github.com/danielgtaylor/huma/v2"
)

const ModuleID = "services"

type Module struct {
	// logFiles is the per-unit allowlist of readable log files (from config),
	// consulted by the file log source.
	logFiles map[string][]string
}

func New(logFiles map[string][]string) *Module { return &Module{logFiles: logFiles} }

func (m *Module) ID() string   { return ModuleID }

// Permissions: read to list and inspect units; write to control them
// (start/stop/restart/enable/disable).
func (m *Module) Permissions() []rbac.Permission {
	return []rbac.Permission{rbac.Read, rbac.Write}
}

func (m *Module) Register(api huma.API) {
	registerServices(api)
	registerLogs(api, m.logFiles)
}

func op(permission string) map[string]any {
	return map[string]any{
		"module":     ModuleID,
		"permission": permission,
	}
}
