include "wamp.fbs";

namespace wamp;


table SessionRolesFilter
{
    /// 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);
}

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

table AuthenticationRequest
{
    realm: string (wampname);
    authid: string (wampname);
    details: SessionDetails;
}

table AuthenticationResponse
{
    realm: string (wampname);
    authid: string (wampname);
    role: string (wampname);
    extra: [KeyValue];
    cache: bool;
}

table AuthorizationRequest
{
    /// The WAMP session to authorize.
    session: SessionDetails;

    /// Fully qualified WAMP URI for which to authorize session.
    uri: string (wampuri);

    /// WAMP action to authorize, e.g. one of `["call", "subscribe", "register", "publish"]`
    action: string;
}

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

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

table Validate
{
    /// WAMP call, the (only or the initial) caller request
    call: string;

    /// WAMP call, any call updates sent by the caller subsequently and while the call
    /// is still active.
    call_progress: string;

    /// WAMP call result, the (only or the initial) callee response
    call_result: string;

    /// WAMP call progressive result, any call result updates sent by the callee subsequently
    /// and while the call is still active.
    call_result_progress: string;

    /// WAMP call error result, the callee error response payload
    call_error: string;

    /// WAMP event published either using normal or router-acknowledged publications
    event: string;

    /// WAMP event confirmation sent by subscribers for subscribed-confirmed publications
    event_confirmation: string;

    /// meta arguments parsed from URI
    extra: [KeyValue];
}

table AuthorizationResponse
{
    allow: Allow;
    disclose: Disclose;
    cache: bool;
    validate: Validate;
}


/// WAMP dynamic authentication API.
rpc_service IWampAuthenticate(type: "interface",
                              uuid: "85da09ef-d3be-467a-acbc-0647a617ef98",
                              wampuri: "wamp")
{
    /// Authenticate a WAMP session to join a realm.
    authenticate (AuthenticationRequest): AuthenticationResponse (type: "procedure",
                                                                  wampuri: "wamp.session.authenticate");

    /// Fired when an authentication of a WAMP session joining a realm was denied.
    on_authentication_denied (AuthenticationRequest): Void (type: "topic",
                                                            wampuri: "wamp.session.on_authentication_denied");
}

/// WAMP dynamic authorization API.
rpc_service IWampAuthorize(type: "interface",
                           uuid: "58c79d59-4b0c-4d1c-9c85-cf80236bd6ad",
                           wampuri: "wamp")
{
    /// Authorize a WAMP session for a WAMP action on a URI on a realm.
    authorize (AuthorizationRequest): AuthorizationResponse (type: "procedure",
                                                             wampuri: "wamp.session.authorize");

    /// Fired when an authorization of a WAMP action on an URI was denied.
    on_authorization_denied (AuthorizationRequest): Void (type: "topic",
                                                          wampuri: "wamp.session.on_authorization_denied");
}
