/* All Rights reserved */


#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import "LedgerModel.h"

@interface LedgerModel : NSObject

{ 
  NSMutableArray *records;
  NSMutableArray *filteredRecords;

  NSCalendarDate *defaultDate;
  NSMutableArray *dates, *categories;
  int new;
  float total;
  float average;
}


- (void) dealloc;
- (id) init;


// Properties methods
//********************


- (NSMutableArray *) records;
- (void) setRecords: (NSMutableArray *) someRecords;

- (NSCalendarDate *) defaultDate;
- (void) setDefaultDate: (NSCalendarDate *) date;

- (NSNumber *) total;
- (NSNumber *) average;
- (NSArray *) dates;
- (NSArray *) categories;

- (void) filterRecords: (NSDictionary *)theFilter;


// Editing methods
//*****************


- (void) addRecord: (NSMutableDictionary *) record;
- (int) newRecord;
- (void) clearNewRecord;


// NSTableViewDataSource protocol methods
//****************************************


- (int) numberOfRowsInTableView: (NSTableView *) view;

- (id)            tableView: (NSTableView *) view
  objectValueForTableColumn: (NSTableColumn *) column
                        row: (int) row;
                        
- (void) tableView: (NSTableView *) view
    setObjectValue: (id) object 
    forTableColumn: (NSTableColumn *) column 
               row: (int) row;
               
               
// NSTableView data source drag and drop methods
//***********************************************


//- (NSDragOperation) tableView: (NSTableView *) view                    
//                validateDrop: (id <NSDraggingInfo>) info                    
//                  proposedRow: (int) row                    
//        proposedDropOperation: (NSTableViewDropOperation) operation;
        
//- (BOOL) tableView: (NSTableView *) view         
//        acceptDrop: (id <NSDraggingInfo>) info
//               row: (int) row         
//     dropOperation: (NSTableViewDropOperation) operation;
     
//- (BOOL) tableView: (NSTableView *) view         
//         writeRows: (NSArray *) rows    
//      toPasteboard: (NSPasteboard *) pboard;


// Private methods and functions
//*******************************


- (void) _sortRecords;
- (void) _computeTotal;
- (void) _updateDates;
- (void) _updateCategories;

int _recordSort(id rec1, id rec2, void *context);


@end
