
{%- if has_input  %}
export async function {{ event_func_name }}(payload: {{ input_deserializer }}): Promise<Result<{{ output_deserializer }}, {{ error_deserializer }}>> {
{%- else %}
export async function {{ event_func_name }}(): Promise<Result<{{ output_deserializer }}, {{ error_deserializer }}>> {
{%- endif %}
    {%- if has_input  %}
    let args = {
        request: {
            ty: {{ event_name }}[{{ event_name }}.{{ event }}],
            payload: Array.from(payload.serializeBinary()),
        },
    };
    {%- else %}
    let args = {
        request: {
            ty: {{ event_name }}[{{ event_name }}.{{ event }}],
            payload: Array.from([]),
        },
    };
    {%- endif %}

    let result: { code: number; payload: Uint8Array } = await invoke("invoke_request", args);
    if (result.code == 0) {
    {%- if has_output  %}
        let object = {{ output_deserializer }}.deserializeBinary(result.payload);
        return Ok(object);
    {%- else %}
        return Ok.EMPTY;
    {%- endif %}
    } else {
        let error = {{ error_deserializer }}.deserializeBinary(result.payload);
        console.log({{ event_func_name }}.name, error);
        return Err(error);
    }
}
