//
//  TBLRNTUtils.m
//  TaboolaReactNativePlugin4x
//
//  Created by Daniel Frimet on 14/05/2025.
//

// TBLRNTUtils.m

#import "TBLRNTUtils.h"
#import "TBLRNTClassicPage.h"
#import "TBLRNTClassicPagesMap.h"
#import "TBLRNTConstants.h"

@implementation TBLRNTUtils

+ (NSString *)generateHashStringForObject:(id)object {
  return [NSString stringWithFormat:@"%lu", (unsigned long)[object hash]];
}

// Helper method to get TBLClassicPage from pageId
+ (nullable TBLRNTClassicPage *)getClassicPageForPageId:(NSString *)pageId {
  if (!pageId || [pageId isEqualToString:@""]) {
    NSLog(@"[TBLRNTUtils] Error: Invalid pageId provided");
    return nil;
  }
  NSMutableDictionary *tblClassicPagesMap =
      [[TBLRNTClassicPagesMap sharedObject] tblClassicPagesMap];
  TBLRNTClassicPage *tblClassicPage =
      [[tblClassicPagesMap objectForKey:pageId] valueForKey:kTBLClassicPageKey];
  if (!tblClassicPage) {
    NSLog(@"[TBLRNTUtils] Error: Classic page is nil for pageId: %@", pageId);
    return nil;
  }

  return tblClassicPage;
}

@end
