/*
 * 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.vinet.data;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import java.time.Instant;

public class IsolateTimeSlot extends TimeSlot implements Datastoreable{
  protected static String ISOLATE_TIME_SLOT_TABLE_NAME = "IsolateTimeSlot";

  protected final String ticketKey;
  protected final DatastoreService datastore;
  protected final String date;

  public IsolateTimeSlot(Instant start, Instant end, Isolate isolate) {
    super(start, end, isolate);
    this.date = "";
    this.ticketKey = "";
    this.datastore = DatastoreServiceFactory.getDatastoreService();
  }

  public IsolateTimeSlot(Instant start, Instant end, Isolate isolate, String date, String ticketKey) {
    super(start, end, isolate);
    this.date = date;
    this.ticketKey = ticketKey;
    this.datastore = DatastoreServiceFactory.getDatastoreService();
  }

  public Isolate getIsolate() {
    return (Isolate) registeredUser;
  }

  /**
   * Put this IsolateTimeSlot into Datstore.
   */
  @Override
  public void toDatastore() {
    /* TODO: Check that all instance variables are non-null before posting to Datastore. */
   final  Entity entity = new Entity(ISOLATE_TIME_SLOT_TABLE_NAME);
    entity.setProperty("ticketKey", ticketKey);
    entity.setProperty("isolateId", this.getIsolate().userId);
    entity.setProperty("date", date);
    entity.setProperty("startTime", start.toString());
    entity.setProperty("endTime", end.toString());
    this.datastore.put(entity);
  }
}

@@ -809,25 +809,100 @@
 ort 
-java.time.Instant
+com.google.appengine.api.datastore.Key;%0Aimport java.time.Instant;%0Aimport java.time.LocalDate
 ;%0A%0Ap
@@ -1067,32 +1067,26 @@
 d final 
-String
+Key
  ticket
-Key
 ;%0A  prot
@@ -1101,64 +1101,67 @@
 nal 
-DatastoreService datastore;%0A  protected final String dat
+LocalDate date;%0A  protected final DatastoreService datastor
 e;%0A%0A
@@ -1228,16 +1228,44 @@
  isolate
+, LocalDate date, Key ticket
 ) %7B%0A    
@@ -1308,18 +1308,20 @@
 .date = 
-%22%22
+date
 ;%0A    th
@@ -1333,16 +1333,17 @@
 cket
-Key = %22%22
+ = ticket
 ;%0A  
@@ -1487,37 +1487,62 @@
 te, 
-String date, String ticketKey
+LocalDate date, Key ticket, DatastoreService datastore
 ) %7B%0A
@@ -1610,19 +1610,16 @@
 s.ticket
-Key
  = ticke
@@ -1619,19 +1619,16 @@
 = ticket
-Key
 ;%0A    th
@@ -1646,53 +1646,17 @@
 e = 
-DatastoreServiceFactory.getDatastoreService()
+datastore
 ;%0A  
@@ -2033,19 +2033,16 @@
 , ticket
-Key
 );%0A    e
@@ -2134,16 +2134,27 @@
 e%22, date
+.toString()
 );%0A    e
@@ -2250,24 +2250,25 @@
 oString());%0A
+%0A
     this.dat

update IsolateTimeSlot.java to include the day of the request