//
//  VolcLiveImpl.m
//  react-native-velive-pull
//
//  Created by ByteDance on 2025/9/18.
//

#import "VeLivePullImpl.h"
#import "VolcApiEngine/VolcEventObserver.h"
#import <React/RCTBridgeModule.h>

@interface  VeLivePullImpl()

@end

@implementation VeLivePullImpl

- (instancetype) initWithModule:(NSObject<EventObserver> *)module {
  self = [super init];
  if (self) {
    self.module = module;
  }
  return self;
}

- (id)newApiEngine {
  if (self.volcApiEngine == nil) {
    self.volcApiEngine = [[VolcApiEngine alloc] init];
    [self.volcApiEngine setObserver:self.module];
  }
  return nil;
}

- (NSDictionary *)callApiSync:(NSDictionary *)args {
  [self newApiEngine];
  return [self.volcApiEngine callApi:args];
}

//callback 是OC的回调函数，外层需要进一步封装，接收一个NSDictionary类型的参数
- (void)callApi:(NSDictionary *)args callback:(void (^)(id))callback {
  [self newApiEngine];
  dispatch_async(dispatch_get_main_queue(), ^{
    id _val = [self.volcApiEngine callApi:args];
    callback(_val);
  });

}

@end
