// Copyright 2019 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 com.google.appengine.api.datastore.EmbeddedEntity;
import java.time.LocalTime;

/** A saleCard. */
public final class SaleCard {

  private final long id;
  private String businessName;
  private String description;
  private LocalTime startTime;
  private LocalTime endTime;
  private LocationData location;
  private Picture picture;

  public SaleCard(long id, String businessName, String description,
      LocalTime startTime, LocalTime endTime, LocationData location, Picture picture) {
    this.id = id;
    this.businessName = businessName;
    this.description = description;
    this.startTime = startTime;
    this.endTime = endTime;
    this.location = location;
    this.picture = picture;
  }

  public SaleCard(EmbeddedEntity embeddedSaleCard) {
    if (embeddedSaleCard == null) {
      this.id = -1;
      return;
    }

    this.id = (long) embeddedSaleCard.getKey().getId();
    this.businessName = (String) embeddedSaleCard.getProperty("businessName");
    this.description = (String) embeddedSaleCard.getProperty("description");
    CharSequence start = (CharSequence) embeddedSaleCard.getProperty("startTime");
    this.startTime = LocalTime.parse(start);
    CharSequence end = (CharSequence) embeddedSaleCard.getProperty("endTime");
    this.endTime = LocalTime.parse(end);
    EmbeddedEntity embeddedLocation = (EmbeddedEntity) embeddedSaleCard.getProperty("location");
    this.location = new LocationData(embeddedLocation);
    EmbeddedEntity embeddedPicture = (EmbeddedEntity) embeddedSaleCard.getProperty("picture");
    this.picture = new Picture(embeddedPicture);
  }

  public long getId() {
    return id;
  }

  public String getBusinessName() {
    return businessName;
  }

  public LocationData getLocation() {
    return location;
  }

  public LocalTime getStartTime() {
    return startTime;
  }

  public LocalTime getEndTime() {
    return endTime;
  }

  public String getDescription() {
    return description;
  }

  public Picture getPic() {
    return picture;
  }

  public void setBusinessName(String businessName) {
    this.businessName = businessName;
  }

  public void setLocation(LocationData location) {
    this.location = location;
  }

  public void setStartTime(LocalTime startTime) {
    this.startTime = startTime;
  }

  public void setEndTime(LocalTime endTime) {
    this.endTime = endTime;
  }

  public void setDescription(String description) {
    this.description = description;
  }

  public void setPic(Picture picture) {
    this.picture = picture;
  }
}
@@ -831,24 +831,55 @@
 escription;%0A
+  private boolean hasDelivery;%0A
   private Lo
@@ -893,24 +893,24 @@
  startTime;%0A
-
   private Lo
@@ -1054,16 +1054,37 @@
 ription,
+ boolean hasDelivery,
 %0A      L
@@ -1252,24 +1252,60 @@
 escription;%0A
+    this.hasDelivery = hasDelivery;%0A
     this.sta
@@ -1753,24 +1753,103 @@
 cription%22);%0A
+    this.hasDelivery = (boolean) embeddedSaleCard.getProperty(%22hasDelivery%22);%0A%0A
     CharSequ
@@ -2084,16 +2084,21 @@
 e(end);%0A
+    %0A
     Embe
@@ -2205,16 +2205,52 @@
 cation =
+ (embeddedLocation == null) : null ?
  new Loc
@@ -2391,16 +2391,51 @@
 icture =
+ (embeddedPicture == null) : null ?
  new Pic
@@ -2585,56 +2585,118 @@
 lic 
-LocationData getLocation() %7B%0A    return location
+String getDescription() %7B%0A    return description;%0A  %7D%0A%0A  public boolean hasDelivery() %7B%0A    return hasDelivery
 ;%0A  
@@ -2829,33 +2829,36 @@
  public 
-String getDescrip
+LocationData getLoca
 tion() %7B
@@ -2861,39 +2861,36 @@
 () %7B%0A    return 
-descrip
+loca
 tion;%0A  %7D%0A%0A  pub
@@ -3054,70 +3054,169 @@
  set
-Location(LocationData location) %7B%0A    this.location = location
+Description(String description) %7B%0A    this.description = description;%0A  %7D%0A%0A  public void setHasDelivery(boolean hasDelivery) %7B%0A    this.hasDelivery = hasDelivery
 ;%0A  
@@ -3405,72 +3405,66 @@
  set
-Description(String description) %7B%0A    this.description = descrip
+Location(LocationData location) %7B%0A    this.location = loca
 tion

Add extra null check