include "wamp.fbs";


namespace wamp;


table SessionRolesFilter (type: "request")
{
    /// The WAMP session authroles to filter for.
    filter_authroles: [string] (arg, wampuri);
}

table SessionIdFilter (type: "request")
{
    /// The WAMP session ID to filter for.
    session_id: uint64 (arg, wampid);
}

table SessionInfo
{
}

table AddTestament
{
    /// The topic to publish the testament to.
    topic: string (arg, wampuri);

    /// A list of arguments for the publish.
    args: [uint8] (arg, cbor);

    /// A dict of keyword arguments for the publish.
    kwargs: [uint8] (arg, cbor);

    /// The publish options for the publish.
    publish_options: KeyValue (kwarg);

    /// The scope of the testament, either "detached" or "destroyed".
    scope: string (kwarg);
}

table FlushTestaments
{
    scope: string (arg);
}

table SessionKill
{
    /// The WAMP session ID of the session to kill.
    session_id: uint64 (arg, wampid);

    /// A reason URI provided to the killed session.
    reason: string (kwarg, wampuri);

    /// A message provided to the killed session.
    message: string (kwarg);
}

table SessionKillByAuthid
{
    /// The WAMP authid of the sessions to kill.
    authid: uint64 (arg, wampid);

    /// A reason URI provided to the killed session(s).
    reason: string (kwarg, wampuri);

    /// A message provided to the killed session(s).
    message: string (kwarg);
}

table SessionKillByAuthrole
{
    /// The WAMP authrole of the sessions to kill.
    authrole: string (arg, wampuri);

    /// A reason URI provided to the killed session(s).
    reason: string (kwarg, wampuri);

    /// A message provided to the killed session(s).
    message: string (kwarg);
}


table RegistrationRemoveCallee
{
    /// The ID of the registration to remove the callee from.
    registration_id: uint64 (arg, wampid);

    /// The WAMP session ID of the callee to remove.
    callee_id: uint64 (arg, wampid);

    // FIXME.
    reason: string (wampuri);
}


table SubscriptionRemoveSubscriber
{
    /// The ID of the subscription to remove the subscriber from.
    subscription_id: uint64 (arg, wampid);

    /// The WAMP session ID of the subscriber to remove.
    subscriber_id: uint64 (arg, wampid);

    // FIXME.
    reason: string (wampuri);
}


/// WAMP meta API.
rpc_service IWampMeta(type: "interface",
                      uuid: "88711231-3d95-44bc-9464-58d871dd7fd7",
                      wampuri: "wamp")
{
    /// Get list of session IDs of sessions currently joined on the router.
    session_list (SessionRolesFilter): WampIds (type: "procedure",
                                             wampuri: "wamp.session.list");

    /// Count sessions currently joined on the router.
    session_count (SessionRolesFilter): Uint (type: "procedure",
                                              wampuri: "wamp.session.count");

    /// Get details for given session.
    session_get (SessionIdFilter): SessionInfo (type: "procedure", wampuri: "wamp.session.count");

    /// A new session has joined the realm.
    session_on_join (Void): Void (type: "topic", wampuri: "wamp.session.on_join");

    /// FIXME.
    session_on_leave (Void): Void (type: "topic", wampuri: "wamp.session.on_leave");

    /// FIXME.
    session_on_stats (Void): Void (type: "topic", wampuri: "wamp.session.on_stats");

    /// Add a testament to the current session.
    session_add_testament (AddTestament): WampId (type: "procedure", wampuri: "wamp.session.add_testament");

    /// Flush the testaments of a given scope for the calling session.
    session_flush_testaments (FlushTestaments): Uint (type: "procedure", wampuri: "wamp.session.flush_testaments");

    /// Forcefully kill a session.
    session_kill (SessionKill): Void (type: "procedure", wampuri: "wamp.session.kill");

    /// Forcefully kill all sessions with given authid.
    session_kill_by_authid (SessionKillByAuthid): WampIds (type: "procedure", wampuri: "wamp.session.kill_by_authid");

    /// Forcefully kill all sessions with given authrole.
    session_kill_by_authrole (SessionKillByAuthrole): WampIds (type: "procedure", wampuri: "wamp.session.kill_by_authrole");

    /// Forcefully remove callee from a registration.
    registration_remove_callee (RegistrationRemoveCallee): Void (type: "procedure", wampuri: "wamp.registration.remove_callee");

    /// A first callee was registered for a registration, and the registration was created in the first place.
    registration_on_create (Void): Void (type: "topic", wampuri: "wamp.registration.on_create");

    /// A callee was registered for a registration.
    registration_on_register (Void): Void (type: "topic", wampuri: "wamp.registration.on_register");

    /// A callee was unregistered from a registration.
    registration_on_unregister (Void): Void (type: "topic", wampuri: "wamp.registration.on_unregister");

    /// The last callee was unregistered from a registration, and the registration was deleted.
    registration_on_delete (Void): Void (type: "topic", wampuri: "wamp.registration.on_delete");

    /// Forcefully remove subscriber from subscription.
    subscription_remove_subscriber (SubscriptionRemoveSubscriber): Void (type: "procedure", wampuri: "wamp.subscription.remove_subscriber");

    /// A first subscriber was subscribed to a subscription, and the subscription was created in the first place.
    subscription_on_create (Void): Void (type: "topic", wampuri: "wamp.subscription.on_create");

    /// A subscriber was subscribed to a subscription.
    subscription_on_subscribe (Void): Void (type: "topic", wampuri: "wamp.subscription.on_subscribe");

    /// A subscriber was unsubscribed from a subscription.
    subscription_on_unsubscribe (Void): Void (type: "topic", wampuri: "wamp.subscription.on_unsubscribe");

    /// The last subscriber was unsubscribed from a subscription, and the subscription was deleted.
    subscription_on_delete (Void): Void (type: "topic", wampuri: "wamp.subscription.on_delete");

    /// Get registration details.
    registration_get (Void): Void (type: "procedure", wampuri: "wamp.registration.get");

    /// Get subscription details.
    subscription_get (Void): Void (type: "procedure", wampuri: "wamp.subscription.get");

    /// List current registrations.
    registration_list (Void): Void (type: "procedure", wampuri: "wamp.registration.list");

    /// List current subscriptions.
    subscription_list (Void): Void (type: "procedure", wampuri: "wamp.subscription.list");

    /// Given a procedure URI, return the registration best matching the procedure.
    registration_match (Void): Void (type: "procedure", wampuri: "wamp.registration.match");

    /// Given a topic URI, returns all subscriptions matching the topic.
    subscription_match (Void): Void (type: "procedure", wampuri: "wamp.subscription.match");

    /// Given a procedure URI (and options), return the registration (if any) managing the procedure.
    registration_lookup (Void): Void (type: "procedure", wampuri: "wamp.registration.lookup");

    /// Given a topic URI (and options), return the subscription (if any) managing the topic.
    subscription_lookup (Void): Void (type: "procedure", wampuri: "wamp.subscription.lookup");

    /// Retrieve list of callees (WAMP session IDs) registered on (attached to) a registration.
    registration_list_callees (Void): Void (type: "procedure", wampuri: "wamp.registration.list_callees");

    /// Retrieve list of subscribers (WAMP session IDs) subscribed on (attached to) a subscription.
    subscription_list_subscribers (Void): Void (type: "procedure", wampuri: "wamp.subscription.list_subscribers");

    /// Retrieve number of callees registered on (attached to) a registration.
    registration_count_callees (Void): Void (type: "procedure", wampuri: "wamp.registration.count_callees");

    /// Retrieve number of subscribers subscribed on (attached to) a subscription.
    subscription_count_subscribers (Void): Void (type: "procedure", wampuri: "wamp.subscription.count_subscribers");

    /// Return history of events for given subscription.
    subscription_get_events (Void): Void (type: "procedure", wampuri: "wamp.subscription.get_events");

    /// Reflection API.
    interface_list (Void): Void (type: "procedure", wampuri: "wamp.interface.list");

    interface_get (Void): Void (type: "procedure", wampuri: "wamp.interface.get");

    interface_match_procedure (Void): Void (type: "procedure", wampuri: "wamp.interface.match_procedure");

    interface_match_topic (Void): Void (type: "procedure", wampuri: "wamp.interface.match_topic");

    type_list (Void): Void (type: "procedure", wampuri: "wamp.type.list");

    type_get (Void): Void (type: "procedure", wampuri: "wamp.type.get");
}
