//go:build !crm

package serverruntime

import (
	"github.com/gin-gonic/gin"
	"github.com/nexuscrm/kernel/pkg/auth"
	"github.com/nexuscrm/shared/pkg/constants"
	"github.com/pingcap-inc/nexuscrm-controlplane/packs"
)

func activeAppPacksFromDefaultCatalog(catalog map[string]bool) []packs.ActiveInstalledAppPack {
	var rows []packs.ActiveInstalledAppPack
	for name, active := range catalog {
		if active {
			rows = append(rows, packs.ActiveInstalledAppPack{Name: name})
		}
	}
	return rows
}

func platformInventoryTestAuth() gin.HandlerFunc {
	return func(c *gin.Context) {
		c.Set(constants.ContextKeyUser, auth.UserSession{ID: "005TESTUSER0001", ProfileId: "00eTESTPROFILE01"})
		c.Next()
	}
}

func platformInventoryTestAuthorization(
	systemPerms map[string]bool,
) gin.HandlerFunc {
	return func(c *gin.Context) {
		c.Set(
			constants.ContextKeyUser,
			auth.UserSession{
				ID:        "005TESTUSER0001",
				ProfileId: "00eTESTPROFILE01",
			},
		)
		c.Set(constants.ContextKeySystemPermissions, systemPerms)
		c.Next()
	}
}
