//
//  SBSwitchboard.h
//  SwitchboardSDK
//
//  Created by Balazs Kiss on 2025. 07. 03..
//

#import <Foundation/Foundation.h>

#import "SBResult.h"

NS_ASSUME_NONNULL_BEGIN

typedef NSString* SBObjectID;
typedef NSString* SBObjectURI;
typedef NSNumber* SBListenerID;

__attribute__((swift_name("Switchboard")))
@interface SBSwitchboard : NSObject

/**
 * Initializes Switchboard SDK with the given configuration.
 *
 * @param config The configuration dictionary.
 *
 * @return A result containing the object URI if successful, or an error if failed.
 */
+ (SBResult<SBObjectURI>*)initializeWithConfig:(NSDictionary<NSString*, id>*)config;

/**
 * Deinitializes Switchboard SDK.
 *
 * @return A result indicating success or failure.
 */
+ (SBResult<NSNull*>*)deinitialize;

/**
 * Creates an engine with the given configuration.
 *
 * @param config The configuration dictionary for the engine.
 *
 * @return A result containing the object ID of the created engine if successful, or an error if failed.
 */
+ (SBResult<SBObjectID>*)createEngineWithConfig:(NSDictionary<NSString*, id>*)config;

/**
 * Creates an engine with the given JSON configuration.
 *
 * @param config The JSON string representing the engine configuration.
 *
 * @return A result containing the object ID of the created engine if successful, or an error if failed
 */
+ (SBResult<SBObjectID>*)createEngineWithJSON:(NSString*)config;

/**
 * Destroys the engine with the given object ID.
 *
 * @param objectID The object ID of the engine to destroy.
 *
 * @return A result indicating success or failure.
 */
+ (SBResult<NSNull*>*)destroyEngineWithObjectID:(SBObjectURI)objectID;

/**
 * Gets the value for the given key from the object with the specified object URI.
 *
 * @param key The key to retrieve the value for.
 * @param objectURI The object URI of the object to retrieve the value from.
 *
 * @return A result containing the value if successful, or an error if failed.
 */
+ (SBResult<id>*)getValueForKey:(NSString*)key object:(SBObjectURI)objectURI;

/**
 * Sets the value for the given key on the object with the specified object URI.
 *
 * @param value The value to set.
 * @param key The key to set the value for.
 * @param objectURI The object URI of the object to set the value on.
 *
 * @return A result indicating success or failure.
 */
+ (SBResult<NSNull*>*)setValue:(id)value forKey:(NSString*)key onObject:(SBObjectURI)objectURI;

/**
 * Calls an action on the object with the specified object URI.
 *
 * @param objectURI The object URI of the object to call the action on.
 * @param actionName The name of the action to call.
 * @param params Optional parameters for the action.
 *
 * @return A result containing the return value of the action if successful, or an error if failed.
 */
+ (SBResult<id>*)callActionWithObject:(SBObjectURI)objectURI
                           actionName:(NSString*)actionName
                               params:(nullable NSDictionary<NSString*, id>*)params;

/**
 * Adds an event listener for the specified event on the object with the given object URI.
 *
 * @param objectURI The object URI of the object to add the listener to.
 * @param eventName The name of the event to listen for.
 * @param callback The callback to be called when the event is triggered.
 *
 * @return A result containing the listener ID if successful, or an error if failed.
 */
+ (SBResult<SBListenerID>*)addEventListener:(SBObjectURI)objectURI
                                  eventName:(NSString*)eventName
                                   callback:(void (^)(NSDictionary* eventData))callback;

/**
 * Removes an event listener with the specified listener ID from the object with the given object URI.
 *
 * @param objectURI The object URI of the object to remove the listener from.
 * @param listenerID The listener ID of the event listener to remove.
 *
 * @return A result indicating success or failure.
 */
+ (SBResult<NSNull*>*)removeEventListener:(SBObjectURI)objectURI listenerID:(SBListenerID)listenerID;

@end

NS_ASSUME_NONNULL_END
