/*
        Copyright (c) 1996, NeXT Software, Inc.
        All rights reserved.

        You may freely copy, distribute and reuse the code in this example.
        NeXT disclaims any warranty of any kind, expressed or implied,
        as to its fitness for any particular use.
*/
#import "Talent.h"

@implementation Talent

- (NSArray *)moviesStarredIn
{
    unsigned i = [roles count];
    NSMutableArray *result = [NSMutableArray arrayWithCapacity:i];
    while (i--) {
        id movie = [[roles objectAtIndex:i] valueForKey:@"movie"];
        if (![result containsObject:movie]) {
	    [result addObject:movie];
	}
    }
    return result;
}

- (void)setFirstName:(NSString *)value
{
    [self willChange];
    [firstName autorelease];
    firstName = [value retain];
}
- (NSString *)firstName { return firstName; }

- (void)setLastName:(NSString *)value
{
    [self willChange];
    [lastName autorelease];
    lastName = [value retain];
}
- (NSString *)lastName { return lastName; }

- (void)setPhoto:(id)value
{
    // a to-one relationship
    [self willChange];
    [photo autorelease];
    photo = [value retain];
}
- (id)photo { return photo; }

- (void)addToRoles:(id)object
{
    // a to-many relationship
    [self willChange];
    [roles addObject:object];
}
- (void)removeFromRoles:(id)object
{
    // a to-many relationship
    [self willChange];
    [roles removeObject:object];
}
- (NSArray *)roles { return roles; }

- (void)addToMoviesDirected:(id)object
{
    // a to-many relationship
    [self willChange];
    [moviesDirected addObject:object];
}
- (void)removeFromMoviesDirected:(id)object
{
    // a to-many relationship
    [self willChange];
    [moviesDirected removeObject:object];
}
- (NSArray *)moviesDirected { return moviesDirected; }


- (void)dealloc
{
    [firstName release];
    [lastName release];
    [photo release];
    [roles release];
    [moviesDirected release];

    [super dealloc];
}

@end
