///////////////////////////////////////////////////////////////////////////////
//
//  Copyright (C) typedef int GmbH and contributors.
//  All rights reserved. Licensed under the MIT open-source license.
//
///////////////////////////////////////////////////////////////////////////////

include "wamp.fbs";

namespace wamp;


struct PermissionAllow
{
    call: bool;
    register: bool;
    publish: bool;
    subscribe: bool;
}

struct PermissionDisclose
{
    caller: bool;
    publisher: bool;
}

table RolePermission
{
    uri: string (wampuri_p);
    match: string;
    allow: PermissionAllow;
    disclose: PermissionDisclose;
    cache: bool;
}

table AuthorizationResponse
{
    allow: PermissionAllow;
    disclose: PermissionDisclose;
    cache: bool;
}

table RoleConfig
{
    // FIXME: add "id: string (wampname);"
    name: string (wampname);
    permissions: [RolePermission];
}

table RealmConfig
{
    name: string (wampname);
    roles: [RoleConfig];
}

table StartRealm
{
    realm_id: string (wampname);
    realm_config: RealmConfig;
    // realm_config: [ubyte] (flexbuffer);
}


/// Realm information (also see :class:`crossbar.worker.types.RouterRealm`).
table RealmInfo
{
    id: string (wampname);
    config: RealmConfig;
    // config: [ubyte] (flexbuffer);
    created: string (wampname);
    roles: [RoleConfig];
    has_router: bool;
    has_service_session: bool;
}

/// Role information (also see :class:`crossbar.worker.types.RouterRealmRole`).
table RoleInfo
{
    id: string (wampname);
    config: RoleConfig;
}

table RealmStats
{
}

table RealmStarted
{
}

table RealmStopped
{
    id: string (arg);
    name: string (arg);
    detached_sessions: [uint64] (wampid);
}


table RoleSelector
{
    realm_id: string (arg, wampname);
    role_id: string (arg, wampname);
}


table LinkSelector
{
    realm_id: string (arg, wampname);
    link_id: string (arg, wampname);
}

table NewRole
{
    realm_id: string (arg, wampname);
    role_id: string (arg, wampname);
}

table RealmId
{
    /// Realm ID within router worker.
    value: string (arg, wampname);
}

table RealmIds
{
    /// List of realm IDs within router worker.
    value: [string] (arg, wampname);
}

table RealmName
{
    /// WAMP realm name
    value: string (arg, wampname);
}


rpc_service INodeControl(type: "interface",
                         uuid: "cb656a1b-548a-4a73-8638-37b1e6d52408",
                         wampuri: "crossbarfabriccenter.node.<node_id:str>.worker.<worker_id:str>")
{
    /// Get realms currently running on this router worker.
    get_router_realms (Void): RealmIds (type: "procedure");

    /// Return realm detail information.
    get_router_realm (RealmId): RealmInfo (type: "procedure");

    /// Return realm detail information.
    get_router_realm_by_name (RealmName): RealmInfo (type: "procedure");

    /// Return realm messaging statistics.
    get_router_realm_stats (RealmId): RealmStats (type: "procedure");

    /// Starts a realm on this router worker.
    start_router_realm (StartRealm): RealmInfo (type: "procedure");

    /// Event fired when an application realm was started on this router worker.
    on_realm_started (RealmInfo): Void (type: "topic");

    /// Stop a realm currently running on this router worker.
    stop_router_realm (RealmId): RealmStopped (type: "procedure");

    /// Event fired when an application realm was stopped on this router worker.
    on_realm_stopped (RealmStopped): Void (type: "topic");

    /// Get roles currently running on a realm running on this router worker.
    get_router_realm_roles (WampName): WampNames (type: "procedure");

    /// Return role detail information.
    get_router_realm_role (RoleSelector): RoleInfo (type: "procedure");

    /// Start a role on a realm running on this router worker.
    start_router_realm_role (NewRole): RoleInfo (type: "procedure");

    /// Event fired when a role was started within an application realm on this router worker.
    on_router_realm_role_started (RoleInfo): Void (type: "topic");

    /// Stop a role currently running on a realm running on this router worker.
    stop_router_realm_role (RoleSelector): RoleInfo (type: "procedure");

    /// Event fired when a role was stopped within an application realm on this router worker.
    on_router_realm_role_stopped (RoleInfo): Void (type: "topic");

    /// Get app components currently running in this router worker.
    get_router_components (Void): WampNames (type: "procedure");

    /// Get details about a router component
    get_router_component (Void): Void (type: "procedure");

    /// Start an app component in this router worker.
    start_router_component (Void): Void (type: "procedure");

    /// Stop an app component currently running in this router worker.
    stop_router_component (Void): Void (type: "procedure");

    /// Get transports currently running in this router worker.
    get_router_transports (Void): Void (type: "procedure");

    /// Get transports currently running in this router worker.
    get_router_transport (Void): Void (type: "procedure");

    /// Start a transport on this router worker.
    start_router_transport (Void): Void (type: "procedure");

    /// Stop a transport currently running in this router worker.
    stop_router_transport (Void): Void (type: "procedure");

    /// Returns the currently running routing links to remote router realms.
    get_router_realm_links (Void): Void (type: "procedure");

    /// Get router link detail information.
    get_router_realm_link (Void): Void (type: "procedure");

    /// Start a new router link to a remote router on a (local) realm.
    start_router_realm_link (Void): Void (type: "procedure");

    /// Stop a currently running router link.
    stop_router_realm_link (Void): Void (type: "procedure");

    ///
    kill_by_authid (Void): Void (type: "procedure");
}
