// Copyright © 2022 BytePlusRTC All rights reserved.
// SPDX-License-Identifier: MIT

//
//  VertcImpl.m
//  react-native-rtc
//
//  Created by ByteDance on 2025/10/28.
//

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

@interface VertcImpl()

@end


@implementation VertcImpl

- (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];
      [VertcApiEngine.sharedInstance setApiEngine:[self volcApiEngine]];
  }
  return nil;
}

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

- (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