package worker

import (
	"context"
	"encoding/json"

	"kra/internal/modules/system/biz"
)

// registerTaskMethods defines the in-process methods available to the task
// management page. Add application-specific registrations here.
func registerTaskMethods(executor *TaskExecutor) {
	biz.RegisterTaskMethod(
		biz.TaskMethodClearDB,
		"清理数据库过期日志(操作记录/JWT黑名单/定时任务执行日志)",
		func(ctx context.Context, _ json.RawMessage) error {
			return executor.tasks.CleanupLogs(ctx)
		},
	)
	biz.RegisterTaskMethod(
		biz.TaskMethodUploads,
		"清理过期大文件上传会话",
		func(ctx context.Context, _ json.RawMessage) error {
			ttl := 24
			config := executor.runtime.Admin()
			if config != nil && config.Media != nil && config.Media.SessionTtl > 0 {
				ttl = int(config.Media.SessionTtl)
			}
			return executor.media.CleanupStale(ctx, ttl)
		},
	)
}
