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

NS_ASSUME_NONNULL_BEGIN

@interface OfflineSyncManager : NSObject

+ (instancetype)shared;

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

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

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

- (void)retryAllFailedHistoryItems;

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

@end

NS_ASSUME_NONNULL_END
