--[[
Ejemplo:
	lua test.lua 192.168.4.11

	donde 192.168.4.11 es la ip de cassandra
]]--
require "json"

-- CASANDRA --------------------------------------------
--
local cassandra = require "lua_cassandra"
local cassandraHost = arg[1] or "127.0.0.1"
local cassandraPort = arg[2] or 9160

print("Connecting CASSANDRA " .. tostring(cassandraHost) .. ":" .. tostring(cassandraPort))
cassandra.seed(cassandraHost, cassandraPort)

-- REDIS --------------------------------------------
--
local WrapRedis = require "wrapredis"
local redisHost = arg[3] or "127.0.0.1"
local redisPort = arg[4] or 6377
local redisPwd = arg[5] or ""
print("Connecting REDIS " .. tostring(redisHost) .. ":" .. tostring(redisPort))
local redis = WrapRedis(redisHost, tonumber(redisPort), redisPwd)
------------------------------------------------------

--local apiRasa = require("rasa"):new()

local apiRasa20 = require("rasa"):new("2.0")

apiRasa20.EnableRasaLogger(true)
apiRasa20.SetRedis(redis)

-- la Config del Webhandler Actual que esta utilizando la Rocka
apiRasa20.SetServerConfig({
	webhandler = { -- 
--		IP = "192.168.4.11",
		IP = "192.168.4.12",
--		IP = "192.168.4.13",
		port = "8082"
	}
})

-- Los otros nodos que tienen un webhandler (aca también llega el WebHandler actual)
local nodes = {
	nodes =  {
		{
			port = "48000",
			IP = "192.168.4.12" -- este es el test la supuesta ip del node actual que esta laburando.
		},
		{
			port = "48000",
			IP = "192.168.4.11" -- el node del webhandler posta
		},
		-- {
		-- 	port = "48000",
		-- 	IP = "192.168.4.13" -- un nodo con la cual estoy probando
		-- }
	}
}
apiRasa20.SetNodes(nodes)

--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------

local function AddApp (info)
	print("")
	print("-- TEST 1 AddApp ---(START)------------")
	local vcc = info.vcc
	local success, response = apiRasa20:AddApp(info, vcc)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 AddApp ---(END)------------")
	print("")
end


-- ---- TEST 1------------------------------------
-- --[[
	-- Crea una nueva App (modelo) de RASA
-- ]]--
local info = {
	name = "rasaapp1",
	description = "Test RASA primera app (rasaapp1)",
	vcc = "vcc1",
	culture = "es"
}
--AddApp(info)
-- --------------------------------------------------

-- ---- TEST 1------------------------------------
-- --[[
	-- Getr App (modelo) de RASA
-- ]]--
local function GetApp (info)
	print("")
	print("-- TEST 1 GetApp ---(START)------------")
	local vcc = info.vcc
	local success, response = apiRasa20:GetApp(info.id, info.vcc)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 GetApp ---(END)------------")
	print("")
end

-- ---- TEST 1------------------------------------
-- --[[
	-- Obtiene la App (modelo) de RASA
-- ]]--
local info = {
	id = "test_rasa_app26",
	vcc = "vcc2"
}
--GetApp(info)

-- ---- TEST 1------------------------------------
-- --[[
	-- Load VCC Apps (modelo) de RASA
-- ]]--
local function LoadApps (info)
	print("")
	print("-- TEST 1 LoadApps ---(START)------------")
	local success, response = apiRasa20:LoadApps(info.vcc)
	print("-----------------")
--	print("-success: " .. tostring(json.encode(success)))
--	print("-response: " .. tostring(response))
	print("-- TEST 1 LoadApps ---(END)------------")
	print("")
end

-- ---- TEST 1------------------------------------
-- --[[
	-- Obtiene las apps del vcc (modelo) de RASA
-- ]]--
local info = {
	vcc = "vcc2"
}
--LoadApps(info)

-- ---- TEST 1------------------------------------
-- --[[
	-- Actualiza la App (modelo) de RASA
-- ]]--
local function RenameApp (info)
	print("")
	print("-- TEST 1 RenameApp ---(START)------------")
	local vcc = info.vcc
	local success, response = apiRasa20:RenameApp(info, vcc)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 RemameApp ---(END)------------")
	print("")
end

-- ---- TEST 1------------------------------------
-- --[[
	-- Actualiza la App (modelo) de RASA
-- ]]--
local info = {
	--id = "test_rasa_app26",
	id = "cany3s@vcc1 - MiniClusterUbuntu",
	name = "test_rasa_app261bbbbbbbb",
	description = "Test RASA primera app (test_rasa_app261bbbbbbbb)",
	vcc = "vcc2",
	culture = "en",
	algo = "afasdfasdfasdfasdfasdfasdfasddddddddddddddddddddddddasdfa"
}
--RenameApp(info)

local function DeleteApp (info)
	print("")
	print("-- TEST 1 DeleteApp ---(START)------------")
	local success, response = apiRasa20:DeleteApp(info.id, info.vcc, info.forceDelete)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 DeleteApp ---(END)------------")
	print("")
end

-- ---- TEST 1------------------------------------
-- --[[
	-- Elimina la App (modelo) de RASA
-- ]]--
local info = {
--	id = "test_rasa_app26",
	id = "rasaapp1",
	vcc = "vcc1"
}
--DeleteApp(info)

--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------

-- ---- TEST 1------------------------------------
-- --[[
	-- Crea una nueva App (modelo) de RASA
-- ]]--
local info = {
	name = "rasa_emma_aapp4",
	description = "Test RASA primera app (rasa_emma_aapp4)",
	vcc = "vcc1",
	culture = "es"
}
--AddApp(info)

-- ---- TEST 2------------------------------------
-- --[[
	-- Train App (modelo) de RASA
-- ]]--

local function TrainApp (info)
	print("")
	print("-- TEST 2 TrainApp ---(START)------------")
	local success, response = apiRasa20:TrainApp(info)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 TrainApp ---(END)------------")
	print("")
end
-- ---------------------------------------------------

local info = {
	--appId = "rasaapp1",
--	appId = "a083c176_b180_4266_91d5_9d074e46a485",
--	appId = "5dff7bcc_9e03_4afb_a313_91bc01bb1b7f",
	appId = "rasa_emma_aapp1",
	vcc = "vcc1",
	makeNLUFile = true,
	userId = "emma@vcc1"
}
--TrainApp(info)

info.id = info.appId
--DeleteApp(info)




-- ---- TEST 1------------------------------------
-- --[[
	-- Crea una nueva App (modelo) de RASA
-- ]]--
local info = {
	name = "rasa_emma_aapp1",
	description = "Test RASA primera app (rasa_emma_aapp1)",
	vcc = "vcc1",
	culture = "es",
	userId = "emma@vcc1"
}
--AddApp(info)

--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------

local function CreateAppFileSystemStructure (info)
	print("")
	print("-- TEST 1 CreateAppFileSystemStructure ---(START)------------")

	local success, response = apiRasa20:CreateAppFileSystemStructure(info)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 CreateAppFileSystemStructure ---(END)------------")
	print("")
end

-- CreateAppFileSystemStructure({
-- 	vcc = info.vcc,
-- 	appId = info.name
-- })

local function DeleteAppFileSystemStructure (info)
	print("")
	print("-- TEST 1 DeleteAppFileSystemStructure ---(START)------------")

	local success, response = apiRasa20:DeleteAppFileSystemStructure(info)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 DeleteAppFileSystemStructure ---(END)------------")
	print("")
end

-- DeleteAppFileSystemStructure({
-- 	vcc = info.vcc,
-- 	appId = info.name
-- })

local function CreateTrainAppFileSystem (info)
	print("")
	print("-- TEST 1 CreateTrainAppFileSystem ---(START)------------")

	local success, response = apiRasa20:CreateTrainAppFileSystem(info)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 CreateTrainAppFileSystem ---(END)------------")
	print("")
end

-- CreateTrainAppFileSystem({
-- 	vcc = info.vcc,
-- 	appId = info.name
-- })


-- ---- TEST 2.a------------------------------------
-- --[[
	-- Run Rasa App A (modelo) de RASA
-- ]]--

local function RunRasaApp (info)
	print("")
	print("-- TEST 2.a RunRasaApp ---(START)------------")
	local success, response = apiRasa20:RunRasaApp(info)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 2.a RunRasaApp ---(END)------------")
	print("")
end
-- ---------------------------------------------------


-- RunRasaApp({
-- 	vcc = info.vcc,
-- 	appId = info.name
-- })


-- local success, response = apiRasa20:LoadAppCultures()
-- print("-----------------")
-- print("-success: " .. tostring(success))
-- print("-response: " .. tostring(response))


--------------------------------------------------------------------------------------
-- INTENT
--------------------------------------------------------------------------------------

-- ---- TEST 1------------------------------------
-- --[[
	-- Crea una nueva App (modelo) de RASA
-- ]]--

local function CreateAppIntent (info)
	print("")
	print("-- TEST 1 CreateAppIntent ---(START)------------")
	local success, response = apiRasa20:CreateAppIntent(info)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 CreateAppIntent ---(END)------------")
	print("")
end

local info = {
	vcc = "vcc1",
	appId = "rasaapp1",
	name = "intent111"
}
--CreateAppIntent(info)

--info.name = "intent1"
--CreateAppIntent(info)

----
-- ---- TEST 1------------------------------------
-- --[[
	-- Get App Intent (modelo) de RASA
-- ]]--
local function GetAppIntent (info)
	print("")
	print("-- TEST 1 GetAppIntent ---(START)------------")
	local vcc = info.vcc
	local success, response = apiRasa20:GetAppIntent(info.appId, info.id, info.vcc)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 GetAppIntent ---(END)------------")
	print("")
end

-- ---- TEST 1------------------------------------
-- --[[
	-- Obtiene un Intent de la App (modelo) de RASA
-- ]]--
local info = {
	id = "intent1",
	appId = "test_rasa_app26",
	vcc = "vcc2"
}
--GetAppIntent(info)

-- ---- TEST 1------------------------------------
-- --[[
	-- Load VCC Apps Intents (modelo) de RASA
-- ]]--
local function LoadAllAppIntents (info)
	print("")
	print("-- TEST 1 LoadAllAppIntents ---(START)------------")
	local success, response = apiRasa20:LoadAllAppIntents(info.appId, info.vcc)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 LoadAllAppIntents ---(END)------------")
	print("")
end

-- ---- TEST 1------------------------------------
-- --[[
	-- Obtiene las apps intents del vcc (modelo) de RASA
-- ]]--
local info = {
	vcc = "vcc1",
	appId = "RasaApp1",
}
--LoadAllAppIntents(info)

-- ---- TEST 1------------------------------------
-- --[[
	-- Actualiza el nombre del Intent de la App (modelo) de RASA
-- ]]--
local function RenameAppIntent (info)
	print("")
	print("-- TEST 1 RenameAppIntent ---(START)------------")
	local success, response = apiRasa20:RenameAppIntent(info)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 RenameAppIntent ---(END)------------")
	print("")
end

-- ---- TEST 1------------------------------------
-- --[[
	-- Actualiza la App (modelo) de RASA
-- ]]--
local info = {
	intentId = "intent111",
	appId = "rasaapp1",
	vcc = "vcc1",
	name = "EmmaIntent1"
}
--RenameAppIntent(info)

local function DeleteAppIntent (info)
	print("")
	print("-- TEST 1 DeleteAppIntent ---(START)------------")
	local vcc = info.vcc
	local success, response = apiRasa20:DeleteAppIntent(info.appId, info.id, info.vcc)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 DeleteAppIntent ---(END)------------")
	print("")
end

-- ---- TEST 1------------------------------------
-- --[[
	-- Elimina la App (modelo) de RASA
-- ]]--
local info = {
	id = "intent111",
	appId = "rasaapp1",
	vcc = "vcc1"
}
--DeleteAppIntent(info)



--------------------------------------------------------------------------------------
-- UTTERANCES
--------------------------------------------------------------------------------------

-- ---- TEST 1------------------------------------
-- --[[
	-- Crea AGREGA UNTTERANCE AL INTENT (modelo) de RASA
-- ]]--

local function AddUtteranceAppIntent (info)
	print("")
	print("-- TEST 1 AddUtteranceAppIntent ---(START)------------")
	local success, response = apiRasa20:AddUtteranceAppIntent(info)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 AddUtteranceAppIntent ---(END)------------")
	print("")
end

local info = {
	vcc = "vcc1",
	appId = "test_rasa_app26",
	intentId = "intent1",
	utterance = "hola Rocio como estas ?"
}
--AddUtteranceAppIntent(info)

--
local info = {
	vcc = "vcc1",
	appId = "app1",
	intentId = "intent1",
	utterance = "welcome Rocio como estas ?"
}
--AddUtteranceAppIntent(info)

info.utterance = "WELCOME EMMA como estas ?"
--AddUtteranceAppIntent(info)

info.utterance = "WELCOME MAMA como estas ?"
--AddUtteranceAppIntent(info)

info.utterance = "WELCOME PAPA como estas ?"
--AddUtteranceAppIntent(info)

local info = {
	vcc = "vcc1",
	appId = "app1",
	intentId = "i1",
	utterance = "hola Rocio como estas ?"
}
--AddUtteranceAppIntent(info)

-- ---- TEST 1------------------------------------
-- --[[
	-- Actualiza los labels de un UNTTERANCE en el INTENT (modelo) de RASA
-- ]]--

local function UpdateUtteranceLabels (info)
	print("")
	print("-- TEST 1 UpdateUtteranceLabels ---(START)------------")
	local success, response = apiRasa20:UpdateUtteranceLabels(info)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 UpdateUtteranceLabels ---(END)------------")
	print("")
end

local info = {
	vcc = "vcc1",
	appId = "app1",
	intentId = "i1",
	utterance = "hola Rocio como estas ?",
	entityLabels = {
		{
			-- entityId       = "vcc1::app1::e1",
			-- entityName     = "e1",
			entityId       = "e1",
			startCharIndex = 5,
			endCharIndex   = 9
		},
		-- {
		-- 	-- entityId       = "vcc1::app1::e2",
		-- 	-- entityName     = "e2",
		-- 	startCharIndex = 11,
		-- 	endCharIndex   = 14
		-- }
	}
}
--UpdateUtteranceLabels(info)

----
-- ---- TEST 1------------------------------------
-- --[[
	-- Get Uttrance App Intent (modelo) de RASA
-- ]]--
local function GetUtteranceByAppIntent (info)
	print("")
	print("-- TEST 1 GetUtteranceByAppIntent ---(START)------------")
	local success, response = apiRasa20:GetUtteranceByAppIntent(info.appId, info.intentId, info.utteranceId, info.vcc)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 GetUtteranceByAppIntent ---(END)------------")
	print("")
end

-- ---- TEST 1------------------------------------
-- --[[
	-- Obtiene un Intent de la App (modelo) de RASA
-- ]]--
local info = {
	utteranceId = "HOLA Rocio como estas ?",
	intentId = "intent1",
	appId = "test_rasa_app26",
	vcc = "vcc2"
}
--GetUtteranceByAppIntent(info)

-- ---- TEST 1------------------------------------
-- --[[
	-- Load Utterances By App Intent ID (modelo) de RASA
-- ]]--
local function LoadUtterancesByIntentId (info)
	print("")
	print("-- TEST 1 LoadUtterancesByIntentId ---(START)------------")
	local success, response = apiRasa20:LoadUtterancesByIntentId(info.appId, info.intentId, info.vcc)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 LoadUtterancesByIntentId ---(END)------------")
	print("")
end

local info = {
	intentId = "i1",
	appId = "app1",
	vcc = "vcc1"
}
--LoadUtterancesByIntentId(info)

-- --[[
	-- Load Utterances By App Intent NAME (modelo) de RASA
-- ]]--
local function LoadUtterancesByIntentName (info)
	print("")
	print("-- TEST 1 LoadUtterancesByIntentName ---(START)------------")
	local success, response = apiRasa20:LoadUtterancesByIntentName(info.appId, info.intentName, info.vcc)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 LoadUtterancesByIntentName ---(END)------------")
	print("")
end

local info = {
	intentName = "i1a",
	appId = "app1",
	vcc = "vcc1"
}
--LoadUtterancesByIntentName(info)




-- ---- TEST 1------------------------------------
-- --[[
	-- Elimina un Utterance del Intent de la App (modelo) de RASA
-- ]]--

local function DeleteAppUtterance (info)
	print("")
	print("-- TEST 1 DeleteAppUtterance ---(START)------------")
	local vcc = info.vcc
	local success, response = apiRasa20:DeleteAppUtterance(info.appId, info.id, info.intentId, info.vcc)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 DeleteUtteranceAppIntent ---(END)------------")
	print("")
end

-- ---- TEST 1------------------------------------
-- --[[
	-- Elimina la App (modelo) de RASA
-- ]]--
local info = {
	vcc = "vcc1",
	appId = "rasaapp1",
	intentId = "intent1",
	id = "welcome Rocio como estas ?"
}
--DeleteAppUtterance(info)

info.id = "WELCOME EMMA como estas ?"
--DeleteAppUtterance(info)

info.id = "WELCOME MAMA como estas ?"
--DeleteAppUtterance(info)

info.id = "WELCOME PAPA como estas ?"
--DeleteAppUtterance(info)

--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
local function MakeNLUFile (info)
	print("")
	print("-- TEST 4 MakeNLUFile ---(START)------------")
	local success, response = apiRasa20:MakeNLUFile(info)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 4 MakeNLUFile ---(END)------------")
	print("")
end

-- ---- TEST 4------------------------------------
-- --[[
	-- MAKE NLU FILE
-- ]]--
local info = {
	appId = "test_rasa_app14",
	vcc = "vcc2",
	content = [[
## intent:IntentVacio

## intent:intent3
- Emma
- Emmita
- Ayelén

## intent:intent2
- Vallejo
- de Mello
- Aquino

## intent:intent1
- Estuve túbulo

## intent:Saludo
- Hola
- qué tal ?
- buenos días
- Hola

## intent:None
- xxxxx
]]
}
--MakeNLUFile(info)
-- ---------------------------------------------------





-- ---- TEST 1------------------------------------
-- --[[
	-- IMPORT LUIS APP (modelo) to RASA desde HDD
-- ]]--

local function LoadJsonFileToImport (fileName)
	local f = io.open(fileName, "rb")
	local content = f:read ("*a")
	f:close()
	--print(content)
	return content
end

local function ImportLuisAppFromHDD (info)
	print("")
	print("-- TEST 1 ImportLuisAppFromHDD ---(START)------------")
	local vcc = info.vcc
	local luisAppJson = LoadJsonFileToImport(info.fileName)
	local luisApp = json.decode(luisAppJson)
	local success, response = apiRasa20:Import(luisApp, vcc)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 ImportLuisAppFromHDD ---(END)------------")
	print("")
end

local info = {
	vcc = "vcc1",
	--fileName = "luisAppCany3s.json"
	fileName = "20201126Pablo_BotAtlas_vNueva.json"
}
--ImportLuisAppFromHDD(info)

-- ---- TEST 1------------------------------------
-- --[[
	-- IMPORT LUIS APP (modelo) to RASA desde la ROCKA de LUIS (API)
-- ]]--

local function ImportLuisAppFromRocka (info)
	print("")
	print("-- TEST 1 ImportLuisAppFromRocka ---(START)------------")
	local vcc = info.vcc
	local success, response = apiRasa20:ImportLuisApp(info.luisAppId, vcc)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. (type(response) == "table" and json.encode(response) or tostring(respone)))
	print("-- TEST 1 ImportLuisAppFromRocka ---(END)------------")
	print("")
end

local info = {
	vcc = "vcc1",
	luisAppId = "a083c176-b180-4266-91d5-9d074e46a485"
}
--ImportLuisAppFromRocka(info)


-- ---- TEST 1------------------------------------
-- --[[
	-- IMPORT LUIS APP (modelo) to RASA desde la ROCKA de LUIS (API)
-- ]]--

local function LoadUnimportedLuisApps (info)
	print("")
	print("-- TEST 1 LoadUnimportedLuisApps ---(START)------------")
	local vcc = info.vcc
	local list, response = apiRasa20:LoadUnimportedLuisApps(vcc)
	print("-----------------")
	print("-success: " .. json.encode(list))
	print("-total: " .. tostring(response))
	print("-- TEST 1 LoadUnimportedLuisApps ---(END)------------")
	print("")
end

local info = {
	vcc = "vcc1"
}
--LoadUnimportedLuisApps(info)




------

-- delete app
local info = {
--	id = "test_rasa_app26",
	id = "cany3s@vcc1 - MiniClusterUbuntu",
	vcc = "vcc1"
}
--DeleteApp(info)

local info = {
--	appId = "cany3s@vcc1 - MiniClusterUbuntu",
	appId = "rasaapp1",
	vcc = "vcc1",
	makeNLUFile = true,
	restart = true
}
--TrainApp(info)


local info = {
	--appId = "rasaapp1",
	appId = "botatlaslocalpablo_vccomni___clusterinconcertcc",
	vcc = "vcc1"
}
--RunRasaApp(info)


-- ---- TEST 2.a------------------------------------
-- --[[
	-- Down Rasa App A (modelo) de RASA
-- ]]--

local function DownRasaApp (info)
	print("")
	print("-- TEST 2.b DownRasaApp ---(START)------------")
	local success, response = apiRasa20:DownRasaApp(info)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 2.b DownRasaApp ---(END)------------")
	print("")
end
-- ---------------------------------------------------

local info = {
	appId = "rasaapp1",
	vcc = "vcc1"
}
--DownRasaApp(info)


-- ---- TEST 3.a------------------------------------
-- --[[
	-- Run Rasa All App of VCC (modelo) de RASA
-- ]]--

local function RunRasaVccApps (info)
	print("")
	print("-- TEST 3.a RunRasaVccApps ---(START)------------")
	local success, response = apiRasa20:RunRasaVccApps(info)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 3.a RunRasaVccApps ---(END)------------")
	print("")
end
-- ---------------------------------------------------

local info = {
	--vcc = "vccQUE_NO_EXISTE"
	vcc = "vcc1"
}
--RunRasaVccApps(info)


-- ---- TEST 3.b------------------------------------
-- --[[
	-- Down All Rasa Apps By Vcc (modelo) de RASA
-- ]]--

local function DownRasaVccApps (info)
	print("")
	print("-- TEST 3.b DownRasaVccApps ---(START)------------")
	local success, response = apiRasa20:DownRasaVccApps(info)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 3.b DownRasaVccApps ---(END)------------")
	print("")
end
-- ---------------------------------------------------

local info = {
	--vcc = "vccQUE_NO_EXISTE"
	vcc = "vcc1"
}
--DownRasaVccApps(info)


-- ---- TEST 4.a------------------------------------
-- --[[
	-- Run Rasa All App of all VCC (modelo) de RASA
-- ]]--

local function RunRasaAllVccsApps ()
	print("")
	print("-- TEST 4.a RunRasaAllVccsApps ---(START)------------")
	local success, response = apiRasa20:RunRasaAllVccsApps()
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 4.a RunRasaAllVccsApps ---(END)------------")
	print("")
end
-- ---------------------------------------------------
--RunRasaAllVccsApps(info)

-- ---- TEST 4.b------------------------------------
-- --[[
	-- Down Rasa All App of all VCC (modelo) de RASA
-- ]]--

local function DownRasaAllVccsApps ()
	print("")
	print("-- TEST 4.b DownRasaAllVccsApps ---(START)------------")
	local success, response = apiRasa20:DownRasaAllVccsApps()
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 4.b DownRasaAllVccsApps ---(END)------------")
	print("")
end
-- ---------------------------------------------------
--DownRasaAllVccsApps(info)

--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
local function Query (info)
	print("")
	print("-- TEST 3 Query ---(START)------------")
	local success, response, luisFormatResponse = apiRasa20:Query(info)
	print("-------------1----")
	print("-success: " .. tostring(success))
	print("-response: " .. (type(response) == "table" and json.encode(response) or tostring(response)))
	print("-luisFormatResponse: " .. (type(luisFormatResponse) == "table" and json.encode(luisFormatResponse) or tostring(luisFormatResponse)))
	print("-- TEST 3 Query ---(END)1------------")
	print("")
end

---- TEST 3------------------------------------
--[[
	RUNTIME QUERY
]]--
local info = {
	convertOnLuis20Response = false,
	appId ="botatlaslocalpablo_vccomni___clusterinconcertcc",
	vcc = "vcc1",
	query = {
		-- text = "si"
		--text = "buen dia"
		--text = "perro"
	--	text = "banana"
		 -- text = "no"
		--text = "adios"
		--text = "pasame con una persona"
		--text = "tienda"
		--text = "lunes"
		--text = "abre la tienda"
		--text = "abre la tienda lunes"
		--text = "How many days in January"
		--text = "Bye"
		--text = "Cuantos dias en Agosto"
		--text = "Cuantos dias en Enero"
		--text = "mujeres"
		--text = "hombres"
		--text = "enero"
		--text = "Cuantas mujeres en Enero"
		--text = "Cuantos dias en Enero"
		--text = "Cuantos dias"
		--text = "emma"
		text = "estupendo"
	--	text = "tu"
	--	text = "hola emma como estas tu ? uno dos tres cuatro"
	}
}
--Query(info)

local info = {
	convertOnLuis20Response = true,
	appId ="a083c176_b180_4266_91d5_9d074e46a485",
	vcc = "vcc1",
	query = {
		text = "manzana podrida"
	}
}
--Query(info)
-- ---------------------------------------------------

--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
local function AppStatus (info)
	print("")
	print("-- TEST 10 AppStatus ---(START)------------")
	local success, response = apiRasa20:AppStatus(info)
	print("-------------1----")
	print("-success: " .. tostring(success))
	print("-response: " .. (type(response) == "table" and json.encode(response) or tostring(response)))
	print("-- TEST 10 AppStatus ---(END)1------------")
	print("")
end

-- ---- TEST 3------------------------------------
-- --[[
	-- RUNTIME APP STATUS
-- ]]--
local info = {
	appId = "a083c176_b180_4266_91d5_9d074e46a485",
	--appId = "borrame1",
	vcc = "vcc1"
}
--AppStatus(info)
-- ---------------------------------------------------

local info = {
	--appId = "botatlaslocalpablo_vccomni___clusterinconcertcc",
	--appId = "borrame1",
	appId = "app1",
	vcc = "vcc1",
--	makeNLUFile = false,
	makeNLUFile = true,
}
--TrainApp(info)

--------------------------
local info = {
	--appId = "rasaapp1",
	appId = "botatlaslocalpablo_vccomni___clusterinconcertcc",
	vcc = "vcc1"
}
--RunRasaApp(info)



--------------------------------------------------------------------------------------
-- ENTITY
--------------------------------------------------------------------------------------

-- ---- TEST 1------------------------------------
-- --[[
	-- Crea una nueva Entidad en la App (modelo) de RASA
-- ]]--

local function CreateAppEntity (info)
	print("")
	print("-- TEST 1 CreateAppEntity ---(START)------------")
	local success, response = apiRasa20:CreateAppEntity(info)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 CreateAppEntity ---(END)------------")
	print("")
end

local info = {
	vcc = "vcc1",
	appId = "botatlaslocalpablo_vccomni___clusterinconcertcc",
	name = "entidad3"
	--name = "entidadEmma1"
}
--CreateAppEntity(info)


----
-- ---- TEST 1------------------------------------
-- --[[
	-- Get App Entity (modelo) de RASA
-- ]]--
local function GetAppEntity (info)
	print("")
	print("-- TEST 1 GetAppEntity ---(START)------------")
	local vcc = info.vcc
	local success, response = apiRasa20:GetAppEntity(info.appId, info.id, info.vcc)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 GetAppEntity ---(END)------------")
	print("")
end

-- ---- TEST 1------------------------------------
-- --[[
	-- Obtiene un Entity de la App (modelo) de RASA
-- ]]--
local info = {
	id = "entidad2",
	appId = "botatlaslocalpablo_vccomni___clusterinconcertcc",
	vcc = "vcc1"
}
--GetAppEntity(info)

-- ---- TEST 1------------------------------------
-- --[[
	-- Load VCC Apps Entities (modelo) de RASA
-- ]]--
local function LoadAllAppEntities (info)
	print("")
	print("-- TEST 1 LoadAllAppEntities ---(START)------------")
	local success, response = apiRasa20:LoadAllAppEntities(info.appId, info.vcc)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 LoadAllAppEntities ---(END)------------")
	print("")
end

-- ---- TEST 1------------------------------------
-- --[[
	-- Obtiene las apps ENTITIES del vcc (modelo) de RASA
-- ]]--
local info = {
	vcc = "vcc1",
	appId = "botatlaslocalpablo_vccomni___clusterinconcertcc",
}
--LoadAllAppEntities(info)

-- ---- TEST 1------------------------------------
-- --[[
	-- Actualiza el nombre de la Entidad de la App (modelo) de RASA
-- ]]--
local function RenameAppEntity (info)
	print("")
	print("-- TEST 1 RenameAppEntity ---(START)------------")
	local success, response = apiRasa20:RenameAppEntity(info)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 RenameAppEntity ---(END)------------")
	print("")
end

-- ---- TEST 1------------------------------------
-- --[[
	-- Actualiza la Entidad de la App (modelo) de RASA
-- ]]--
local info = {
	entityId = "entidad2",
	appId = "botatlaslocalpablo_vccomni___clusterinconcertcc",
	vcc = "vcc1",
	name = "entidad2b"
}
--RenameAppEntity(info)

local function DeleteAppEntity (info)
	print("")
	print("-- TEST 1 DeleteAppEntity ---(START)------------")
	local vcc = info.vcc
	local success, response = apiRasa20:DeleteAppEntity(info.appId, info.id, info.vcc)
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 DeleteAppEntity ---(END)------------")
	print("")
end

-- ---- TEST 1------------------------------------
-- --[[
	-- Elimina la entidad de la App (modelo) de RASA
-- ]]--
local info = {
	id = "entidad3",
	appId = "botatlaslocalpablo_vccomni___clusterinconcertcc",
	vcc = "vcc1"
}
--DeleteAppEntity(info)

-- info.name = info.id
-- CreateAppEntity(info)

-- info.entityId = "entidad3"
-- info.name = "entidad3b"
-- RenameAppEntity(info)


---------

local info = {
	id = "intento1",
	appId = "botatlaslocalpablo_vccomni___clusterinconcertcc",
	vcc = "vcc1"
}
--DeleteAppIntent(info)

-- info.name = info.id
-- info.id = nil
-- CreateAppIntent(info)

-- info.intentId = "intento1"
-- info.name = "intento3"
-- RenameAppIntent(info)

-- info.appId =  "app1"
--LoadAllAppIntents(info)

---------

----
-- UTTERANCES ETIQUETADOS CON ENTIDADES
---

local info = {
	vcc = "vcc1",
	-- appId = "botatlaslocalpablo_vccomni___clusterinconcertcc",
	-- intentId = "afirmacion",
	appId = "app1",
	intentId = "sucursales",
	utterance = "hi emma como estas ?",
	entityLabels = {
		{
			entityId       = "vcc1::app1::e1",
			entityName     = "e1",
			startCharIndex = 3,
			endCharIndex   = 6
		},
		{
			entityId       = "vcc1::app1::e2",
			entityName     = "e2",
			startCharIndex = 9,
			endCharIndex   = 12
		}
	}
}
--AddUtteranceAppIntent(info)

local info = {
	vcc = "vcc1",
	-- appId = "botatlaslocalpablo_vccomni___clusterinconcertcc",
	-- intentId = "afirmacion",
	appId = "app1",
	intentId = "i1",
	utterance = "hi emma como estas ?"
}
--AddUtteranceAppIntent(info)


local info = {
	vcc = "vcc1",
	appId = "botatlaslocalpablo_vccomni___clusterinconcertcc",
	intentId = "afirmacion",
	id = "welcome Rocio como estas ?",
}
--DeleteAppUtterance(info)


local info = {
	utteranceId = "welcome Rocio como estas ?",
	intentId = "afirmacion",
	appId = "botatlaslocalpablo_vccomni___clusterinconcertcc",
	vcc = "vcc1"
}
--GetUtteranceByAppIntent(info)

local info = {
	id = "Afirmacion",
	appId = "botatlaslocalpablo_vccomni___clusterinconcertcc",
	vcc = "vcc1"
}
--GetAppIntent(info)

--DeleteAppIntent(info)

local info = {
	name = "Afirmacion",
	appId = "botatlaslocalpablo_vccomni___clusterinconcertcc",
	vcc = "vcc1"
}
--CreateAppIntent(info)

---
local info = {
--	id = "20201126pablo_botatlas_vnueva",
	id = "botatlaslocalpablo_vccomni___clusterinconcertcc",
	vcc = "vcc1"
}
--DeleteApp(info)

local info = {
	vcc = "vcc1",
	luisAppId = "a083c176-b180-4266-91d5-9d074e46a485"
}
--ImportLuisAppFromRocka(info)

local info = {
	appId = "botatlaslocalpablo_vccomni___clusterinconcertcc",
	vcc = "vcc1"
}
--MakeNLUFile(info)

local info = {
	name = "app1",
	description = "app1",
	vcc = "vcc1",
	culture = "en"
}
--AddApp(info)


info.id = info.name
--DeleteApp(info)


info.culture = "BRASILERO"
--RenameApp(info)

------------------------------------

local function ListenerPublications (info)
	print("")
	print("-- TEST 2 ListenerPublications ---(START)------------")
	local success, response = apiRasa20:ListenerPublications()
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(response))
	print("-- TEST 1 ListenerPublications ---(END)------------")
	print("")
end
---- Aca se ejecuta la actualizacion entre nodos
ListenerPublications()

local appId = "app1"

local info = {
	vcc = "vcc1",
	userId = "emma@vcc1"
}
--LoadApps(info)

--info.name = "rasaapp1"
info.name = appId
info.description = "Test RASA primera app (" .. info.name .. ")"
info.culture = "es"
--AddApp(info)

local intentId = "i1"
info.appId = appId
info.name = intentId
--CreateAppIntent(info)
--LoadAllAppIntents(info)

info.intentId = intentId
info.utterance = "welcome Rocio como estas ?"
--AddUtteranceAppIntent(info)


info.appId = appId
info.makeNLUFile = true
--TrainApp(info)

info.id = appId
--info.forceDelete = true -- por si quedo algo mal en un train (pendiente o algo) y la quiero eliminar igual de la BD y HDD de forma forzada.
--DeleteApp(info)


local info = {
	convertOnLuis20Response = true,
	appId = appId,
	vcc = "vcc1",
	query = {
		text = "manzana podrida"
	}
}
--Query(info)

local function LoadPublications (info)
	print("")
	print("-- TEST 2 LoadPublications ---(START)------------")
	local success, response = apiRasa20:LoadPublications()
	print("-----------------")
	print("-success: " .. tostring(success))
	print("-response: " .. tostring(json.encode(response)))
	print("-- TEST 1 LoadPublications ---(END)------------")
	print("")
end
--LoadPublications()
