/*
 Flash: Flashcard program
 Copyright (C) 2005, Niko Matsakis (niko@alum.mit.edu)
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#import "ConnTracker.h"
#import "Accessors.h"

@implementation ConnTracker

- initWithConnection:(NSManagedObject*)connection
{
    return [self initWithConnection:connection useFromWord:YES];
}

- initWithConnection:(NSManagedObject*)connection useFromWord:(BOOL)fromword
{
    [super init];
    if (fromword)
        _word = [connection fromValue];
    else
        _word = [connection toValue];    
    _relationship = [connection typeValue];
    return self;
}

- (NSManagedObject*) word
{
    return _word;
}

- (NSManagedObject*) relationship
{
    return _relationship;
}

- (unsigned) hash
{
    return [_word hash] + [_relationship hash];
}

- (BOOL) isEqual:object
{
    if (![object isKindOfClass:[self class]])
        return NO;
    
    ConnTracker *ct = (ConnTracker*)object;
    return _word == ct->_word && _relationship == ct->_relationship;
}

- (NSString*) description
{
    return [NSString stringWithFormat:@"[Word#%@ Rel:%@]", 
        [_word idValue], [_relationship nameValue]];
}

// We are immutable, so we can just do this:
- copyWithZone:(NSZone*)zone
{
    return [self retain];
}

@end