//
//  FuelService.m
//  TopUp
//
//  Created by Frank McPherson on 5/20/10.
//  Copyright 2010 intrepidinnovations.com. All rights reserved.
//

#import "FuelService.h"


@implementation FuelService
@synthesize serviceDate;
@synthesize costPerUnit;
@synthesize odometerValue;
@synthesize fuelAdded;
@synthesize totalCost;
@synthesize currency;
@synthesize location;
@synthesize fuelEconomyStyle;

// TODO FHM Designated initializer should allow setting of all the items, 
// so I can pass in as default the previous values
- (id)initWithServiceDate:(NSDate *)date
			  costPerUnit:(NSNumber *)unitCost
			odometerValue:(NSNumber *)odometer
				fuelAdded:(NSNumber *)fuel
				totalCost:(NSNumber *)cost
				 currency:(NSString *)theCurrency
				 location:(CLLocation *)where
		 fuelEconomyStyle:(IIFuelEconomyStyle)style
{
	self = [super init];
	if (self) {
		[self setServiceDate:date];
		[self setCostPerUnit:unitCost];
		[self setOdometerValue:odometer];
		[self setFuelAdded:fuel];
		[self setTotalCost:cost];
		[self setCurrency:theCurrency];
		[self setLocation:where];
		[self setFuelEconomyStyle:style];
	}
	
	return self;
}

- (id)initWithServiceDate:(NSDate *)date
{
	[self initWithServiceDate:date
				  costPerUnit:[NSNumber numberWithFloat:0.0f]
				odometerValue:[NSNumber numberWithInt:0]
					fuelAdded:[NSNumber numberWithFloat:0.0f]
					totalCost:[NSNumber numberWithFloat:0.0f]
					 currency:@"USD"
					 location:nil
			 fuelEconomyStyle:IIFuelEconomyStyleUSMPG];
	
	return self;
}

- (id)init
{
	return [self initWithServiceDate:[NSDate date]];
}

- (id)initWithCoder:(NSCoder *)decoder 
{
	[super init];
	[self setServiceDate:[decoder decodeObjectForKey:@"serviceDate"]];
	[self setCostPerUnit:[decoder decodeObjectForKey:@"costPerUnit"]];
	[self setOdometerValue:[decoder decodeObjectForKey:@"odometerValue"]];
	[self setFuelAdded:[decoder decodeObjectForKey:@"fuelAdded"]];
	[self setTotalCost:[decoder decodeObjectForKey:@"totalCost"]];
	[self setCurrency:[decoder decodeObjectForKey:@"currency"]];
	[self setLocation:[decoder decodeObjectForKey:@"location"]];
	return self;
}

- (void)encodeWithCoder:(NSCoder *)encoder
{
	[encoder encodeObject:serviceDate forKey:@"serviceDate"];
	[encoder encodeObject:costPerUnit forKey:@"costPerUnit"];
	[encoder encodeObject:odometerValue forKey:@"odometerValue"];
	[encoder encodeObject:fuelAdded forKey:@"fuelAdded"];
	[encoder encodeObject:totalCost forKey:@"totalCost"];
	[encoder encodeObject:currency forKey:@"currency"];
	[encoder encodeObject:location forKey:@"location"];
}

- (void)dealloc
{
	[serviceDate release];
	[costPerUnit release];
	[odometerValue release];
	[fuelAdded release];
	[totalCost release];
	[currency release];
	[location release];
	[super dealloc];
}
@end
