package packages

import (
	"nadir/internal/rbac"

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

const ModuleID = "packages"

type Module struct {
	pm manager // detected package manager; zero value means none found
}

// New detects the host's package manager once at startup.
func New() *Module { return &Module{pm: detect()} }

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

// Permissions: read to list installed/available; write to install, remove, and
// upgrade.
func (m *Module) Permissions() []rbac.Permission {
	return []rbac.Permission{rbac.Read, rbac.Write}
}

func (m *Module) Register(api huma.API) {
	registerPackages(api, m.pm)
}

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