//
//  OCSTreeItem.h
//  iStorageMac
//
//  Created by Ondřej Čada on 11/22/11.
//  Copyright (c) 2011 OCSoftware. All rights reserved.
//


typedef NS_ENUM(NSInteger, ISTMetadataType) {
    ISTMetadataTypeFile = 0,
    ISTMetadataTypeClipboard
};

#define kMetadataSizeKey        @"bytes"
#define kMetadataFilePathKey    @"path"
#define kMetadataIsDirKey       @"is_dir"
#define kMetadataCreationKey    @"creation"
#define kMetadataTypeKey        @"type"


@interface ISTMetadata : NSObject

- (instancetype) initWithDictionary:(NSDictionary *)dict;
- (void) setDictionary:(NSDictionary *)dict;

@property (nonatomic, strong) NSString *filename;
@property (nonatomic, strong) NSString *path;
@property (nonatomic, assign) NSUInteger totalBytes;
@property (nonatomic, assign, getter = isDirectory) BOOL directory;

@property (nonatomic, assign, getter = isDownloading) BOOL downloading;
@property (nonatomic, assign, getter = isUploading) BOOL uploading;
@property (nonatomic, assign) double transportProgress;

@property (nonatomic, strong) NSDate *creationDate;

@property (nonatomic, readonly) NSURL *localURL;
@property (nonatomic, readonly) NSString *localPath;

@property (nonatomic, assign) ISTMetadataType type;

@end


// simple tree item: contains a dictionary of subitems (by name) and mditem representing its contents
@interface ISTTreeItem : NSObject

@property (strong) ISTMetadata *metadata;
@property (weak, readonly) NSURL *url; // only for those with an item
@property (copy) NSString *pathName;
@property (weak) ISTTreeItem *parentItem; // beware assigned!

- (ISTTreeItem *) subitemForName:(NSString *)pathName; // created if does not exist yet
- (ISTTreeItem *) itemExistsWithName:(NSString *)pathName;

+ (ISTTreeItem *) item;

// bindings (used in XIB)
@property (nonatomic, readonly, copy) NSImage *ocs_fileIcon;
@property (nonatomic, readonly, copy) NSString *ocs_fileName;
@property (nonatomic, readonly, copy) NSString *ocs_filePath;
@property (nonatomic, readonly, copy) NSString *ocs_fileInfo;
@property (nonatomic, readonly, copy) NSDate *ocs_fileCreationDate;
@property (nonatomic, readonly, copy) NSNumber *ocs_fileProgress;
@property (nonatomic, readonly, copy) NSArray *ocs_children;

// convenience
@property (readonly) BOOL isTransporting;

// merging support
- (void) mergeInTreeItemRecursively:(ISTTreeItem *)anotherItem;

// since the tree controller does not store the root item, but only its children, we need also
+ (void) mergeChildrenOfTreeItemRecursively:(ISTTreeItem *)anotherItem toItems:(NSMutableArray *)items;
// note it is assumed the 'items' "mutable set" is in fact a smart proxy which manages KVO properly on adding/removing objects (happens to be true with KVC-compliant objects if mutableSetValueForKey is used properly)

@end
