/***
 * Excerpted from "iOS SDK Development",
 * published by The Pragmatic Bookshelf.
 * Copyrights apply to this code. It may not be used to create training material, 
 * courses, books, articles, and the like. Contact us if you are in doubt.
 * We make no guarantees that this code is fit for any purpose. 
 * Visit http://www.pragmaticprogrammer.com/titles/adios for more book information.
***/
//
//  PRPRecipesSource.m
//  Recipes
//
//  Created by Bill Dudney on 9/14/12.
//  Copyright (c) 2012 Pragmatic Programmers LLC. All rights reserved.
//

#import "PRPRecipesSource.h"
#import "PRPRecipe.h"

@interface PRPRecipesSource()

@property(nonatomic, strong) NSMutableArray *recipes;

@end

@implementation PRPRecipesSource

- (NSArray *)recipes {
  if(!_recipes) {
    self.recipes = [NSMutableArray array];
    PRPRecipe *recipe = [[PRPRecipe alloc] init];
    recipe.directions = @"0 - Put some stuff in, and the other stuff, then stir";
    recipe.preparationTime = [NSNumber numberWithInt:30];
    recipe.title = @"0 - One Fine Food";
    recipe.image = [UIImage imageNamed:@"cookies.jpg"];
    [self.recipes addObject:recipe];
    
    recipe = [[PRPRecipe alloc] init];
    recipe.directions = @"1 - Put some stuff in, and the other stuff, then stir";
    recipe.preparationTime = [NSNumber numberWithInt:31];
    recipe.title = @"1 - One Fine Food";
    recipe.image = [UIImage imageNamed:@"cookies.jpg"];
    [self.recipes addObject:recipe];
    
    recipe = [[PRPRecipe alloc] init];
    recipe.directions = @"2 - Put some stuff in, and the other stuff, then stir";
    recipe.preparationTime = [NSNumber numberWithInt:32];
    recipe.title = @"2 - One Fine Food";
    recipe.image = [UIImage imageNamed:@"cookies.jpg"];
    [self.recipes addObject:recipe];
    
    recipe = [[PRPRecipe alloc] init];
    recipe.directions = @"3 - Put some stuff in, and the other stuff, then stir";
    recipe.preparationTime = [NSNumber numberWithInt:33];
    recipe.title = @"3 - One Fine Food";
    recipe.image = [UIImage imageNamed:@"cookies.jpg"];
    [self.recipes addObject:recipe];
    
    recipe = [[PRPRecipe alloc] init];
    recipe.directions = @"4 - Put some stuff in, and the other stuff, then stir";
    recipe.preparationTime = [NSNumber numberWithInt:34];
    recipe.title = @"4 - One Fine Food";
    recipe.image = [UIImage imageNamed:@"cookies.jpg"];
    [self.recipes addObject:recipe];
    
    recipe = [[PRPRecipe alloc] init];
    recipe.directions = @"5 - Put some stuff in, and the other stuff, then stir";
    recipe.preparationTime = [NSNumber numberWithInt:35];
    recipe.title = @"5 - One Fine Food";
    recipe.image = [UIImage imageNamed:@"cookies.jpg"];
    [self.recipes addObject:recipe];
    
    NSString *directions = @"Put the flour and other dry ingredients in a bowl, \
    stir in the eggs until evenly moist. Add chocolate chips and stir in until even. \
    Place tablespoon sized portions on greased cookie sheet and bake at 350° for \
    6 minutes.";
    recipe = [[PRPRecipe alloc] init];
    recipe.title = @"Chocolate Chip Cookies";
    recipe.image = [UIImage imageNamed:@"cookies.jpg"];
    recipe.directions = directions;
    recipe.preparationTime = [NSNumber numberWithInt:13];
    [self.recipes addObject:recipe];
  }
  return _recipes;
}

#pragma mark Recipe List Data Source Methods

//
- (NSUInteger)indexOfRecipe:(PRPRecipe *)recipe {
  return [self.recipes indexOfObject:recipe];
}
//

- (NSInteger)recipeCount {
  return [self.recipes count];
}

- (PRPRecipe *)recipeAtIndex:(NSInteger)index {
  return [self.recipes objectAtIndex:index];
}

- (void)deleteRecipeAtIndex:(NSInteger)index {
  [self.recipes removeObjectAtIndex:index];
}

- (PRPRecipe *)createNewRecipe {
  PRPRecipe *recipe = [[PRPRecipe alloc] init];
  [self.recipes addObject:recipe];
  return recipe;
}

@end
