// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.sps.data;

import java.util.List;
import java.util.Objects;

public final class Recipe {

  private final String name;
  private final String time;
  private final String calories;
  private final String difficulty;
  private final List<String> dietaryRequirements;
  private final List<String> ingredients;
  private final List<String> instructions;
  private final int recipeId;

  public Recipe(
      String name,
      String time,
      String calories,
      String difficulty,
      List<String> dietaryRequirements,
      List<String> ingredients,
      List<String> instructions) {
    this.name = name;
    this.time = time;
    this.calories = calories;
    this.difficulty = difficulty;
    this.dietaryRequirements = dietaryRequirements;
    this.ingredients = ingredients;
    this.instructions = instructions;
    this.recipeId = this.hashCode();
  }

  @Override
  public boolean equals(Object other) {
    if (this == other) return true;
    if (other == null || getClass() != other.getClass()) return false;
    Recipe recipe = (Recipe) other;
    return name.equals(recipe.name) &&
            time.equals(recipe.time) &&
            calories.equals(recipe.calories) &&
            difficulty.equals(recipe.difficulty) &&
            dietaryRequirements.equals(recipe.dietaryRequirements) &&
            ingredients.equals(recipe.ingredients) &&
            instructions.equals(recipe.instructions);
  }

  @Override
  public int hashCode() {
    int multiplier = 31;
    int result = Objects.hash(name, time, calories, difficulty);
    result = multiplier * result + dietaryRequirements.hashCode();
    result = multiplier * result + ingredients.hashCode();
    result = multiplier * result + instructions.hashCode();
    return result;
  }

  @Override
  public String toString() {
    return "name: " + name + "\n"
        + "time: " + time + "\n" 
        + "calories: " + calories + "\n" 
        + "difficulty: " + difficulty + "\n"
        + "diet: " + dietaryRequirements + "\n" 
        + "ingredients: " + ingredients + "\n" 
        + "instructions: " + instructions;
  }
}

@@ -1699,19 +1699,16 @@
 pe.name)
- &&
 %0A       
@@ -1708,19 +1708,18 @@
         
-   
+&&
  time.eq
@@ -1735,29 +1735,25 @@
 pe.time)
- &&%0A 
+%0A
         
    calor
@@ -1744,18 +1744,18 @@
         
-  
+&&
  calorie
@@ -1779,19 +1779,16 @@
 alories)
- &&
 %0A       
@@ -1788,19 +1788,18 @@
         
-   
+&&
  difficu
@@ -1827,19 +1827,16 @@
 ficulty)
- &&
 %0A       
@@ -1836,19 +1836,18 @@
         
-   
+&&
  dietary
@@ -1889,37 +1889,33 @@
 equirements)
- &&%0A 
+%0A
         
    ingredien
@@ -1902,18 +1902,18 @@
         
-  
+&&
  ingredi
@@ -1943,19 +1943,16 @@
 edients)
- &&
 %0A       
@@ -1952,19 +1952,18 @@
         
-   
+&&
  instruc
@@ -2130,16 +2130,57 @@
 culty);%0A
+    if (dietaryRequirements != null) %7B%0A  
     resu
@@ -2230,32 +2230,38 @@
 nts.hashCode();%0A
+    %7D%0A
     result = mul

Fix null pointer exception for dietary requirements