package com.google.sps.data;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.Entity;
import com.google.sps.service.DatabaseService;
import java.util.Date;

public abstract class Lesson {

    public static final String LESSON_ENTITY_NAME = "Lesson";
    public static final String ISDRAFT_PROPERTY_KEY = "isDraft";
    public static final String TITLE_PROPERTY_KEY = "title";
    public static final String DESCRIPTION_PROPERTY_KEY = "description";
    // public static final String TAGS_PROPERTY_KEY = "tags";
    public static final String DATE_PROPERTY_KEY = "date";

    private Entity entity;

    public Lesson(Entity entity) {
        this.entity = entity;
    }

    public Lesson(String title, String description) {
        this.entity = new Entity(Lesson.LESSON_ENTITY_NAME);
        this.entity.setProperty(Lesson.ISDRAFT_PROPERTY_KEY, false);
        this.entity.setProperty(Lesson.TITLE_PROPERTY_KEY, title);
        this.entity.setProperty(Lesson.DESCRIPTION_PROPERTY_KEY, description);
        this.entity.setProperty(Lesson.DATE_PROPERTY_KEY, new Date());
    }

    public Entity getLessonEntity() {
        return this.entity;
    }

    public boolean getIsDraft() {
        return (boolean) this.entity.getProperty(Lesson.ISDRAFT_PROPERTY_KEY);
    }

    public void publish() {
        this.entity.setProperty(Lesson.ISDRAFT_PROPERTY_KEY, true);
    }

    public void unpublish() {
        this.entity.setProperty(Lesson.ISDRAFT_PROPERTY_KEY, false);
    }

    public String getTitle() {
        return (String) this.entity.getProperty(Lesson.TITLE_PROPERTY_KEY);
    }

    public void setTitle(String title) {
        this.entity.setProperty(Lesson.TITLE_PROPERTY_KEY, title);
    }

    public String getDescription() {
        return (String) this.entity.getProperty(Lesson.DESCRIPTION_PROPERTY_KEY);
    }

    public void setDescription(String description) {
        this.entity.setProperty(Lesson.DESCRIPTION_PROPERTY_KEY, description);
    }

}
@@ -189,16 +189,183 @@
 il.Date;
+%0Aimport com.google.sps.data.Form;%0Aimport java.io.IOException;%0Aimport com.google.gson.JsonParser;%0Aimport com.google.gson.JsonElement;%0Aimport com.google.gson.JsonObject;
 %0A%0Apublic
@@ -448,24 +448,83 @@
 = %22Lesson%22;%0A
+    public static final String TYPE_PROPERTY_KEY = %22type%22;%0A
     public s
@@ -832,16 +832,245 @@
 date%22;%0A%0A
+    public static final String TYPE_FORM = %22form%22;%0A    public static final String TYPE_VIDEO = %22video%22;%0A    public static final String TYPE_IMAGE = %22image%22;%0A    public static final String TYPE_CONTENT = %22content%22;          %0A    %0A
     priv
@@ -1182,24 +1182,37 @@
 sson(String 
+type, String 
 title, Strin
@@ -1289,16 +1289,81 @@
 _NAME);%0A
+        this.entity.setProperty(Lesson.TYPE_PROPERTY_KEY, type);%0A
         
@@ -1712,32 +1712,144 @@
 .entity;%0A    %7D%0A%0A
+    public String getType() %7B%0A        return (String) this.entity.getProperty(Lesson.TYPE_PROPERTY_KEY);%0A    %7D%0A%0A
     public boole
@@ -2655,9 +2655,1005 @@
 %0A    %7D%0A%0A
+    public Date getDate()%7B%0A        return (Date) this.entity.getProperty(Lesson.DATE_PROPERTY_KEY);%0A    %7D%0A%0A    // public static Lesson serializeJson(String json) throws IOException %7B%0A    //     JsonObject jobject = JsonParser.parseString(json).getAsJsonObject();%0A%0A    //     switch(jobject.get(Lesson.TYPE_PROPERTY_KEY).getAsString()) %7B%0A    //         case Lesson.TYPE_FORM:%0A    //             return new Form(jobject.get(Lesson.TITLE_PROPERTY_KEY).getAsString(), %0A    //                 jobject.get(Lesson.DESCRIPTION_PROPERTY_KEY).getAsString(), jobject.get(Form.EDIT_URL_PROPERTY_KEY).getAsString(),%0A    //                 jobject.get(Form.URL_PROPERTY_KEY).getAsString());%0A    //         // case Lesson.TYPE_VIDEO:%0A    //         //     return;%0A    //         // case Lesson.TYPE_IMAGE:%0A    //         //     return;%0A    //         // case Lesson.TYPE_CONTENT:%0A    //         //     return;%0A    //         default:%0A    //             throw new IOException(); %0A    //     %7D%0A        %0A    // %7D%0A%0A
 %7D

Create more fields, draft serialize function