class {{ event_class }} {
{%- if has_input  %}
     {{ input_deserializer }} request;
     {{ event_class }}(this.request);
{%- else %}
    {{ event_class }}();
{%- endif %}

    Future<Either<{{ output_deserializer }}, {{ error_deserializer }}>> send() {

{%- if has_input  %}
    final request = FFIRequest.create()
          ..event = {{ event }}.toString()
          ..payload = requestToBytes(this.request);

    return Dispatch.asyncRequest(request)
        .then((bytesResult) => bytesResult.fold(

        {%- if has_output  %}
           (okBytes) => left({{ output_deserializer }}.fromBuffer(okBytes)),
        {%- else %}
           (bytes) => left(unit),
        {%- endif %}
           (errBytes) => right({{ error_deserializer }}.fromBuffer(errBytes)),
        ));

{%- else %}
     final request = FFIRequest.create()
        ..event = {{ event }}.toString();
        {%- if has_input  %}
        ..payload = bytes;
        {%- endif %}

     return Dispatch.asyncRequest(request).then((bytesResult) => bytesResult.fold(
     {%- if has_output  %}
        (okBytes) => left({{ output_deserializer }}.fromBuffer(okBytes)),
     {%- else %}
        (bytes) => left(unit),
     {%- endif %}
        (errBytes) => right({{ error_deserializer }}.fromBuffer(errBytes)),
      ));
{%- endif %}
    }
}

