/*
  Copyright (C) 2000-2003 SKYRIX Software AG

  This file is part of OGo

  OGo is free software; you can redistribute it and/or modify it under
  the terms of the GNU Lesser General Public License as published by the
  Free Software Foundation; either version 2, or (at your option) any
  later version.

  OGo 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 Lesser General Public
  License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with OGo; see the file COPYING.  If not, write to the
  Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  02111-1307, USA.
*/
// $Id$

#include "iCalPerson.h"
#include "common.h"

@implementation iCalPerson

- (void)dealloc {
  [self->rsvp     release];
  [self->partStat release];
  [self->role     release];
  [self->xuid     release];
  [self->email release];
  [self->cn    release];
  [super dealloc];
}

/* accessors */

- (void)setCn:(NSString *)_s {
  ASSIGNCOPY(self->cn, _s);
}
- (NSString *)cn {
  return self->cn;
}

- (void)setEmail:(NSString *)_s {
  ASSIGNCOPY(self->email, _s);
}
- (NSString *)email {
  return self->email;
}

- (void)setRsvp:(NSString *)_s {
  ASSIGNCOPY(self->rsvp, _s);
}
- (NSString *)rsvp {
  return self->rsvp;
}

- (void)setXuid:(NSString *)_s {
  ASSIGNCOPY(self->xuid, _s);
}
- (NSString *)xuid {
  return self->xuid;
}

- (void)setRole:(NSString *)_s {
  ASSIGNCOPY(self->role, _s);
}
- (NSString *)role {
  return self->role;
}

- (void)setPartStat:(NSString *)_s {
  ASSIGNCOPY(self->partStat, _s);
}
- (NSString *)partStat {
  return self->partStat;
}

/* comparison */

- (unsigned)hash {
  if([self email])
    return [[self email] hash];
  return [super hash];
}

- (BOOL)isEqual:(id)_other {
  if(_other == nil)
    return NO;
  if([_other class] != self->isa)
    return NO;
  if([_other hash] != [self hash])
    return NO;
  return [self isEqualToPerson:_other];
}

- (BOOL)isEqualToPerson:(iCalPerson *)_other {
  if(![self hasSameEmailAddress:_other])
    return NO;
  if(!IS_EQUAL([self cn], [_other cn], isEqualToString:))
    return NO;
  if(!IS_EQUAL([self rsvp], [_other rsvp], isEqualToString:))
    return NO;
  if(!IS_EQUAL([self partStat], [_other partStat], isEqualToString:))
    return NO;
  if(!IS_EQUAL([self role], [_other role], isEqualToString:))
    return NO;
  if(!IS_EQUAL([self xuid], [_other xuid], isEqualToString:))
    return NO;
  return YES;
}

- (BOOL)hasSameEmailAddress:(iCalPerson *)_other {
  return IS_EQUAL([self email], [_other email], isEqualToString:);
}

/* descriptions */

- (NSString *)description {
  NSMutableString *ms;

  ms = [NSMutableString stringWithCapacity:128];
  [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];

  if (self->cn)       [ms appendFormat:@" cn=%@",     self->cn];
  if (self->email)    [ms appendFormat:@" email=%@",  self->email];
  if (self->role)     [ms appendFormat:@" role=%@",   self->role];
  if (self->xuid)     [ms appendFormat:@" uid=%@",    self->xuid];
  if (self->partStat) [ms appendFormat:@" status=%@", self->partStat];
  if (self->rsvp)     [ms appendFormat:@" rsvp=%@",   self->rsvp];

  [ms appendString:@">"];
  return ms;
}

@end /* iCalPerson */
