{%- if index == 0 %}
{{ imported_dart_files }}
{%- endif -%}

class {{ event_class }} {
    {{ input_deserializer }} request;
    {{ event_class }}(this.request);

    Future<Either<{{ output_deserializer }}, FlowyError>> send() {
    return requestToBytes(request).fold(
        (bytes) {
          final request = FFIRequest.create()
            ..event = {{ event }}.toString()
            ..payload = bytes;

          return Dispatch.asyncRequest(request)
              .then((bytesResult) => bytesResult.fold(
                    (bytes) => left({{ output_deserializer }}.fromBuffer(bytes)),
                    (error) => right(error),
                  ));
        },
        (err) => Future(() => right(err)),
        );
    }
}

