module RSRES {

/* Implementation of the REmote Sim RESt (RSRES) JSON data types in TTCN-3.
 * (C) 2019 by Harald Welte <laforge@gnumonks.org>
 * All rights reserved.
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 */

import from RSPRO all;

/* resembles "enum remsim_server_client_fsm_state" */
type enumerated ConnectionState {
	INIT,
	ESTABLISHED,
	CONNECTED_CLIENT,
	CONNECTED_BANKD
};

type record JsBank {
	charstring		peer,
	ConnectionState		state,
	ComponentIdentity	component_id,
	BankId			bankId,
	SlotNumber		numberOfSlots
};
type record of JsBank JsBanks;

template JsBank tr_JsBank(template ConnectionState state,
			  template ComponentIdentity comp_id,
			  template BankId bank_id,
			  template SlotNumber num_of_slots) := {
	peer := ?,
	state := state,
	component_id := comp_id,
	bankId := bank_id,
	numberOfSlots := num_of_slots
}

type record JsClient {
	charstring		peer,
	ConnectionState		state,
	ComponentIdentity	component_id
};
type record of JsClient JsClients;

template JsClient tr_JsClient(template ConnectionState state,
			  template ComponentIdentity comp_id) := {
	peer := ?,
	state := state,
	component_id := comp_id
}

/* resembles "enum slot_mapping_state" */
type enumerated SlotmapState {
	NEW,
	UNACKNOWLEDGED,
	ACTIVE,
	DELETE_REQ,
	DELETING
};

type record JsSlotmap {
	BankSlot		bank,
	ClientSlot		client,
	SlotmapState		state optional
};
type record of JsSlotmap JsSlotmaps;

template (value) JsSlotmap ts_JsSlotmap(template (value) BankSlot bslot,
					template (value) ClientSlot cslot,
					template (omit) SlotmapState state := omit) := {
	bank := bslot,
	client := cslot,
	state := state
}
template JsSlotmap tr_JsSlotmap(template BankSlot bslot,
				template ClientSlot cslot,
				template SlotmapState state := ?) := {
	bank := bslot,
	client := cslot,
	state := state
}



/* root JSON type expressing what remsim-server can return */
type record JsRoot {
	JsClients		clients optional,
	JsBanks			banks optional,
	JsSlotmaps		slotmaps optional
};

external function f_enc_JsRoot(in JsRoot inp) return octetstring
	with { extension "prototype(convert) encode(JSON)" }
external function f_dec_JsRoot(in octetstring inp) return JsRoot
	with { extension "prototype(convert) decode(JSON)" }

external function f_enc_JsSlotmap(in JsSlotmap inp) return octetstring
	with { extension "prototype(convert) encode(JSON)" }
external function f_dec_JsSlotmap(in octetstring inp) return JsSlotmap
	with { extension "prototype(convert) decode(JSON)" }



} with { encode "JSON" }