package it.danieleverducci.openweddingapp.entities

import org.json.JSONObject

class Table: Jsonable {
    val table: String
    val count: Int
    val people: ArrayList<TablePeople>

    constructor(jo: JSONObject) {
        this.table = jo.getString("table")
        this.count = jo.getInt("count")
        val peopleJa = jo.getJSONArray("people")
        this.people = ArrayList()
        for (i in 0 until peopleJa.length())
            this.people.add(TablePeople(peopleJa.getJSONObject(i)))
    }

    override fun toJson(): JSONObject {
        TODO("Never used")
    }

    fun getPeoplePrintableList(): String {
        var pl = ""
        this.people.forEach {
            if (pl.length > 0)
                pl += ", "
            pl += it.name
        }
        return pl
    }
}


class TablePeople {
    val name: String
    val surname: String

    constructor(jo: JSONObject) {
        this.name = jo.getString("name")
        this.surname = jo.getString("surname")
    }
}