// Copyright 2020 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

// (Re-)generated by schema tool
// >>>> DO NOT CHANGE THIS FILE! <<<<
// Change the json schema instead

#![allow(dead_code)]
#![allow(unused_imports)]

use timestamp::*;
use wasmlib::*;
use wasmlib::host::*;

use crate::consts::*;
use crate::keys::*;
use crate::results::*;
use crate::state::*;

mod consts;
mod contract;
mod keys;
mod results;
mod state;
mod timestamp;

#[no_mangle]
fn on_load() {
    let exports = ScExports::new();
    exports.add_func(FUNC_NOW,           func_now_thunk);
    exports.add_view(VIEW_GET_TIMESTAMP, view_get_timestamp_thunk);

    unsafe {
        for i in 0..KEY_MAP_LEN {
            IDX_MAP[i] = get_key_id_from_string(KEY_MAP[i]);
        }
    }
}

pub struct NowContext {
	state: MutabletimestampState,
}

fn func_now_thunk(ctx: &ScFuncContext) {
	ctx.log("timestamp.funcNow");
	let f = NowContext {
		state: MutabletimestampState {
			id: OBJ_ID_STATE,
		},
	};
	func_now(ctx, &f);
	ctx.log("timestamp.funcNow ok");
}

pub struct GetTimestampContext {
	results: MutableGetTimestampResults,
	state: ImmutabletimestampState,
}

fn view_get_timestamp_thunk(ctx: &ScViewContext) {
	ctx.log("timestamp.viewGetTimestamp");
	let f = GetTimestampContext {
		results: MutableGetTimestampResults {
			id: OBJ_ID_RESULTS,
		},
		state: ImmutabletimestampState {
			id: OBJ_ID_STATE,
		},
	};
	view_get_timestamp(ctx, &f);
	ctx.log("timestamp.viewGetTimestamp ok");
}
