#import <objc/runtime.h>
#import <objc/message.h>
#import <Foundation/Foundation.h>

static BOOL disableStorySeen = YES;

static void (*orig_setSeenState)(id, SEL, id) = NULL;

static void hook_setSeenState(id self, SEL _cmd, id state) {
  if (disableStorySeen) return;
  if (orig_setSeenState) orig_setSeenState(self, _cmd, state);
}

__attribute__((constructor))
static void init() {
  @autoreleasepool {
    Class cls = objc_getClass("FBSnacksSurfaceAwareSeenStateWriter");
    if (!cls) {
      fprintf(stderr, "[noseen] FBSnacksSurfaceAwareSeenStateWriter not found\n");
      return;
    }

    SEL sel = @selector(setSeenState:);
    Method m = class_getInstanceMethod(cls, sel);
    if (!m) {
      fprintf(stderr, "[noseen] setSeenState: not found on %s\n", class_getName(cls));
      return;
    }

    orig_setSeenState = (void (*)(id, SEL, id))method_getImplementation(m);
    method_setImplementation(m, (IMP)hook_setSeenState);
    fprintf(stderr, "[noseen] hooked setSeenState: on %s\n", class_getName(cls));
  }
}
