package it.danieleverducci.openweddingapp.entities

import org.json.JSONException
import org.json.JSONObject
import java.text.SimpleDateFormat
import java.util.*

class Like: Jsonable {
    val id: Int
    val galleryId: Int
    val userId: Int
    val created: Date

    @Throws(JSONException::class)
    constructor(jo: JSONObject) {
        this.id = jo.getInt("id")
        this.galleryId = jo.getInt("gallery_id")
        this.userId = jo.getInt("user_id")
        this.created = SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(jo.getString("created"))
    }


    constructor(galleryId: Int, userId: Int) {
        this.id = 0
        this.galleryId = galleryId
        this.userId = userId
        this.created = Date()
    }

    override fun toJson(): JSONObject {
        val jo = JSONObject()
        jo.put("id", this.id)
        jo.put("gallery_id", this.galleryId)
        jo.put("user_id", this.userId)
        jo.put("created", this.created)
        return jo
    }
}