//
//  Immeuble.m
//  Agence
//
//  Created by Olivier Savard on 11-01-21.
//  Copyright 2011 OSInfo Informatique. All rights reserved.
//

#import "Immeuble.h"


@implementation Immeuble
@synthesize immeubleID;
@synthesize type;
@synthesize style;
@synthesize adresse;
@synthesize prix;
@synthesize distance;
@synthesize latitude;
@synthesize longitude;
@synthesize coordinate;

#pragma mark NSCoding
-(void)setCoordinate:(CLLocationCoordinate2D)newCoordinate{
	newCoordinate.latitude = self.latitude;
	newCoordinate.longitude = self.longitude;
	coordinate = newCoordinate;
}

-(NSString *)title {
	return self.style;
}

-(NSString *)subtitle {
	
	return ([NSString stringWithFormat:@"%@" ,adresse]);
	
	/*
	if(rue)
		[ret appendString:rue];
	if(rue && (ville || province || codePostal))
		[ret appendString:@", "];
	if (ville)
		[ret appendString:ville];
	if (ville && province)
		[ret appendString:@", "];
	if (province)
		[ret appendString:province];
	if (codePostal){
		[ret appendString:@", "];
		[ret appendString:codePostal];
	}*/
	
	
}



-(void)encodeWithCoder:(NSCoder *)aCoder {
	[aCoder encodeInt:immeubleID forKey:kFieldID];
	[aCoder encodeInt:type		forKey:kFieldType];
	[aCoder encodeObject:style		forKey:kFieldStyle];
	[aCoder encodeObject:adresse	forKey:kFieldAdresse];
	[aCoder encodeInt:distance		forKey:kFieldDistance];
	[aCoder encodeInt:prix		forKey:kFieldPrix];
	[aCoder encodeDouble:latitude forKey:kFieldLatitude];
	[aCoder encodeDouble:longitude forKey:kFieldLongitude];	
}

-(id)initWithCoder:(NSCoder *)aDecoder {
	if (self = [super init]) {
		self.immeubleID = [aDecoder decodeIntForKey:kFieldID];
		self.type = [aDecoder decodeIntForKey:kFieldType];
		self.style = [aDecoder decodeObjectForKey:kFieldStyle];
		self.adresse = [aDecoder decodeObjectForKey:kFieldAdresse];
		self.distance = [aDecoder decodeIntForKey:kFieldDistance];
		self.prix = [aDecoder decodeIntForKey:kFieldPrix];
		self.latitude = [aDecoder decodeDoubleForKey:kFieldLatitude];
		self.longitude = [aDecoder decodeDoubleForKey:kFieldLongitude];
		CLLocationCoordinate2D newCoord;
		[self setCoordinate:newCoord];
	}
	return self;
}

-(id)copyWithZone:(NSZone *)zone
{
	Immeuble *copy = [[[self class] allocWithZone: zone ] init];
	copy.immeubleID = self.immeubleID;
	copy.type = self.type;
	copy.style = [ self.style copy];
	copy.adresse = [ self.adresse copy];
	copy.distance = self.distance;
	copy.prix = self.prix;
	copy.latitude = self.latitude;
	copy.longitude = self.longitude;
	copy.coordinate = self.coordinate;
	return copy;
}
	

-(void)dealloc{
	style.release;
	adresse.release;
	[super dealloc];
}

@end
