// OfflineSyncManager.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface OfflineSyncManager : NSObject

+ (instancetype)shared;
- (NSMutableArray *)safeLoadQueue;
- (void)saveQueue:(NSArray *)queue;

// Queue actions
- (void)queueAddIssue:(NSDictionary *)payload
              display:(NSDictionary *)display
               images:(NSArray<UIImage *> *)images
           fieldNames:(NSDictionary *)fieldNames;

- (void)queueUpdateIssue:(NSDictionary *)payload
                 display:(NSDictionary *)display
                  images:(NSArray<UIImage *> *)images
              fieldNames:(NSDictionary *)fieldNames;


- (void)queueAddInfo:(NSString *)issueID
             remarks:(NSString *)remarks
         displayInfo:(NSDictionary *)displayInfo
              images:(NSArray<UIImage *> *)images
            mediaURL:(NSURL * _Nullable)mediaURL
           mediaType:(NSString * _Nullable)mediaType;

// Helpers
- (BOOL)hasPendingItems;

- (NSArray *)pendingItemsForUI;
- (NSArray *)historyItemsForUI;

- (void)clearOfflineQueue;

- (void)processNextItemWithProgress:(void (^)(NSInteger step,
                                              NSInteger total,
                                              NSString *title))progress
                         completion:(void (^)(BOOL finished))completion;

// Retry failed history item
- (void)retryHistoryItem:(NSDictionary *)historyItem;

// Download Units
- (void)startDownloadUnitImagesWithProgress:(void (^)(NSInteger completed, NSInteger total))progress
                                 completion:(void (^)(BOOL success))completion;

@end

NS_ASSUME_NONNULL_END
