extern "C" {
#include "dittoffi.h"
}

#include "retainable.h"

#ifdef SWIG
%feature("director", assumeoverride=1) AttachmentObserverRust;
%apply(char *STRING, size_t LENGTH) { (const unsigned char *id_ptr, uintptr_t id_len) };
#endif
class AttachmentObserverRust: public Retainable {
public:
  virtual ~AttachmentObserverRust() {}
  virtual void completedEventHandler(
    const struct AttachmentHandle *ah
  ) = 0;

  virtual void progressEventHandler(
    uint64_t downloadedBytes,
    uint64_t totalBytes
  ) = 0;

  virtual void deletedEventHandler(
  ) = 0;

  static void invokeCompletedEventHandler(
    void *ctx,
    struct AttachmentHandle *ah
  ) {
    auto inst = static_cast<AttachmentObserverRust*>(ctx);
    return inst->completedEventHandler(
      ah
    );
  }

  static void invokeProgressEventHandler(
    void *ctx,
    uint64_t downloadedBytes,
    uint64_t totalBytes
  ) {
    auto inst = static_cast<AttachmentObserverRust*>(ctx);
    return inst->progressEventHandler(
      downloadedBytes,
      totalBytes
    );
  }

  static void invokeDeletedEventHandler(
    void *ctx
  ) {
    auto inst = static_cast<AttachmentObserverRust*>(ctx);
    return inst->deletedEventHandler(
    );
  }

  virtual CancelTokenResult_t resolve_attachment(
    struct CDitto *ditto_raw,
    const unsigned char *id_ptr,
    uintptr_t id_len
  ) {
     return ditto_resolve_attachment(
       ditto_raw,
       (slice_ref_uint8_t) {
           .ptr = id_ptr,
           .len = id_len,
       },
       this,
       AttachmentObserverRust::invokeRetain,
       AttachmentObserverRust::invokeRelease,
       AttachmentObserverRust::invokeCompletedEventHandler,
       AttachmentObserverRust::invokeProgressEventHandler,
       AttachmentObserverRust::invokeDeletedEventHandler
     );
  }
};
