@compiler >= 6

include "String.aes"
include "token.aes"

main contract Context =
    record context =
        { key : string, value: string, meta: string}
    record state =
        { owner      : address,
          contexts   : map(address, map(string, context)) }

    stateful entrypoint init() : state =
        { owner = Call.caller,
          contexts = {} }

    function require_owner() =
        require(Call.caller == state.owner, "only_owner_call_allowed")

    stateful entrypoint add_context( key: string, value: string, meta: string) : bool =
        require(Map.lookup(Call.caller, state.contexts) != None, "Address not registered.")
        put(state{contexts[Call.caller][key] = {key = key, value = value, meta = meta}})
        true

    entrypoint get_context() : map(string, context) =
        require(Map.lookup(Call.caller, state.contexts) != None, "Address not registered.")
        state.contexts[Call.caller]
