//
//  DriveDetail.m
//  Hitch a Ride
//
//  Created by Signity Solutions on 04/07/14.
//  Copyright (c) 2014 Hitch a Ride. All rights reserved.
//

#import "DriveDetail.h"

@implementation DriveHitcherDetail

-(id)init{
    self = [super init];
	if (self != nil) {
        _hitcherId        =[[NSMutableString alloc]init];
        _name            =[[NSMutableString alloc]init];
        _fbid            =[[NSMutableString alloc]init];
        _chatKey         =[[NSMutableString alloc]init];
        _destinationLat  =[[NSMutableString alloc]init];
        _destinationLng  =[[NSMutableString alloc]init];
        _pickupLat       =[[NSMutableString alloc]init];
        _pickupLng       =[[NSMutableString alloc]init];
        _price           =[[NSMutableString alloc]init];
        _hitchId         =[[NSMutableString alloc]init];
        _pickup          =[[NSMutableString alloc]init];
        _destination     =[[NSMutableString alloc]init];

	}
	return self;
}
- (void)resetAllStrings{
    [_hitcherId       setString:@""];
    [_name            setString:@""];
    [_fbid            setString:@""];
    [_chatKey         setString:@""];
    [_destinationLat setString:@""];
    [_destinationLng setString:@""];
    [_pickupLat setString:@""];
    [_pickupLng setString:@""];
    [_price setString:@""];
    [_hitchId setString:@""];
    [_pickup setString:@""];
    [_destination setString:@""];
    
}

- (void)updateHitcherInfoWithAttributes:(NSDictionary *)attributes{
    [self resetAllStrings];
    if ([attributes allKeys].count>5) {
        _isDriveHitcher=YES;
        [_name setString:[attributes objectForKey:@"name"]];
        [_chatKey setString:[attributes objectForKey:@"chat_key"]];
        [_hitcherId setString:[attributes objectForKey:@"user_id"]];
        [_fbid setString:[attributes objectForKey:@"facebook_id"]];
        if([attributes.allKeys containsObject:@"current_latitude"])
            _currentLat=[[attributes objectForKey:@"current_latitude"]floatValue];
        else
            _currentLat=0.0;
        
        if([attributes.allKeys containsObject:@"current_longitude"])
            _currentLng=[[attributes objectForKey:@"current_longitude"]floatValue];
        else
            _currentLng=0.0;
        
        [_destination setString:[attributes objectForKey:@"destination"]];
        [_destinationLat setString:[attributes objectForKey:@"destination_latitude"]];
        [_destinationLng setString:[attributes objectForKey:@"destination_longitude"]];
        [_price setString:[attributes objectForKey:@"offer_price"]];
        [_pickup  setString:[attributes objectForKey:@"pick_up_location"]];
        [_pickupLat setString:[attributes objectForKey:@"pick_up_latitude"]];
        [_pickupLng setString:[attributes objectForKey:@"pick_up_longitude"]];
        [_hitchId   setString:[attributes objectForKey:@"id"]];
    }
    else
        _isDriveHitcher=NO;
}
@end

@implementation DriveDetail

-(id)init{
    self = [super init];
	if (self != nil) {
        _driveId        =[[NSMutableString alloc]init];
        _destination    =[[NSMutableString alloc]init];
        _driveDate      =[[NSMutableString alloc]init];
        _hitchersArray  =[[NSMutableArray alloc] init];
	}
	return self;
}

- (void)updateDriveDetailsWithAttributes:(NSDictionary *)attributes{
    [self resetAllStrings];
    if (attributes.allKeys.count>1) {
        _isDrive=YES;
        [_driveId            setString:[attributes objectForKey:@"id"]];
        [_destination        setString:[attributes objectForKey:@"destination_address"]];
        [_driveDate          setString:[attributes objectForKey:@"leaving_datetime"]];
        _destinationLat     =[[attributes objectForKey:@"destination_latitude"] floatValue];
        _destinationLng     =[[attributes objectForKey:@"destination_longitude"] floatValue];
        [self updateDriveStatus:[[attributes objectForKey:@"status"]intValue]];
      
        [_hitchersArray removeAllObjects];
         _isHitchers=NO;
        if([attributes.allKeys containsObject:@"hitcher"]){
            for (NSDictionary *_dict in (NSArray *)[attributes objectForKey:@"hitcher"]) {
                DriveHitcherDetail *_driveHitcher=[[DriveHitcherDetail alloc]init];
                [_driveHitcher updateHitcherInfoWithAttributes:_dict];
                [_hitchersArray addObject:_driveHitcher];
                 _isHitchers=YES;
            }
        }
    }
    else{
        [_hitchersArray removeAllObjects];
        _isDrive=NO;
        _isHitchers=NO;
    }
}
- (void)updateDriveStatus:(int)statusIndex{
    if(statusIndex==0)
        _status=DSComplete;
    else if (statusIndex==1)
        _status=DSPending;
    else if (statusIndex==2)
        _status=DSCancel;
    else if (statusIndex==3)
        _status=DSStart;
    else
        _status=DSDelete;
}
- (void)resetAllStrings{
    [_driveId        setString:@""];
    [_destination    setString:@""];
    [_driveDate      setString:@""];
}
@end



