#import <Foundation/Foundation.h>

// 2.9.x 의 SGSBase · SGSLog 가 3.0.0 에서 Stove 하나로 통합됐다
#import <Stove/Stove.h>

#import "LogNativeInterface.h"

// MARK: - Extern APIs

void stove_log_add(const char *logEvent, const char *identifier) {
    NSString *nsLogEvent = StoveSDKMakeNSString(logEvent);
    NSString *nsIdentifier = StoveSDKMakeNSString(identifier);
    
    SGSLogEvent *logEventObject = [SGSLogEvent logEventWithDictionary:[nsLogEvent JSONObject]];
    
    [SGSLog addLogEvent:logEventObject completionHandler:^(SGSResult * _Nonnull result) {
        NSDictionary *resultDic = [NSDictionary dictionaryWithObjectsAndKeys:
                                   [result dictionary], @"result",
                                   nil];
        
        StoveSDKNativeCallbackPayload *payload =
        [StoveSDKNativeCallbackPayload payloadWithIdentifier:nsIdentifier value:resultDic];
        [payload sendMessage];
    }];
}

void stove_log_flush() {
    
    [SGSLog flush];
}

const char *stove_log_version() {
    NSString * version = [SGSLog moduleVersion];
    return StoveSDKMakeCString(version);
}

const char *stove_log_sdk_versions() {
    NSDictionary *stoveVersion = [SGSLog SDKVersions];
    NSString *versionString = [stoveVersion JSONString];

    return StoveSDKMakeCString(versionString);
}

void stove_log_set_external_id(const char *externalId) {
    NSString *nsExternalId = StoveSDKMakeNSString(externalId);
    [SGSLog setExternalId:nsExternalId];
}