//
//  GSPathObservation.h
//  GlyphsKit
//
//  Created by Florian Pircher on 02.07.24.
//  Copyright © 2024 schriftgestaltung.de. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <GlyphsKit/GSPathWatcher.h>

NS_ASSUME_NONNULL_BEGIN

/// An abstraction of `GSPathWatcher` in the spirit of `GSKeyValueObservation`.
///
/// See the `GSKeyValueObservation` documentation for a general explanation of the observation object pattern.
@interface GSPathObservation : NSObject <GSPathWatcherObserver>

/// Full path to the observed file or directory.
@property (strong, readonly) NSString *filePath;
/// When greater than zero, target/action is triggered only once the time interval has passed without any new events.
@property (assign) NSTimeInterval debounceDelay;

/// - Parameter action: Parameters: `GSPathObservation *`, returns: `void`.
+ (nullable instancetype)observeFileAtPath:(NSString *)filePath isDirectory:(BOOL)isDirectory target:(NSObject *)target action:(SEL)action;

/// Pauses the observation, performs the block, and resumes the observation before returning.
///
/// Exceptions thrown in the block are caught and rethrown after resuming the observation.
- (void)performBlockWithPausedObservation:(void (^)(void))body;

/// Pauses the observation.
///
/// End the pause by calling `-resumeObservation`.
- (void)pauseObservation;

/// Resumes a paused the observation, balancing a call to `-pauseObservation`.
- (void)resumeObservation;

@end

NS_ASSUME_NONNULL_END
