package system

import (
	"context"
	"time"

	"nadir/internal/rbac"

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

const ModuleID = "system"

type Module struct {
	sampler *Sampler
}

func New() *Module {
	return &Module{
		sampler: NewSampler("/proc/stat", 1*time.Second),
	}
}

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

func (m *Module) Permissions() []rbac.Permission {
	return []rbac.Permission{rbac.Read, rbac.Write, rbac.Root}
}

func (m *Module) Register(api huma.API) {
	m.sampler.Start(context.Background())
	registerInfo(api, m.sampler)
	registerHostname(api)
	registerTimedate(api)
	registerLocale(api)
	registerPower(api)
}

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