package jp.yuta.kohashi.fakelineapp.models

import android.os.Parcel
import android.os.Parcelable
import java.util.*

/**
 * Author : yuta
 * Project name : FakeLineApp
 * Date : 23 / 08 / 2017
 */

// このモデルをjsonに変換して保存する
class TalkData(yourName: String, imgPath: String, calendar: Calendar, isRead: Boolean, items: MutableList<TalkItem>) : Parcelable {

    // トーク相手の名前
    var yourName: String = yourName

    // 画像のパス
    var imgPath: String = imgPath

    // 日付情報
    var calendar: Calendar = calendar

    // 既読チェックボックス
    var isRead: Boolean = isRead

    // トークアイテムリスト
    var items: MutableList<TalkItem> = items

    constructor(source: Parcel) : this(
            source.readString(),
            source.readString(),
            source.readSerializable() as Calendar,
            1 == source.readInt(),
            source.createTypedArrayList(TalkItem.CREATOR)
    )

    override fun describeContents() = 0

    override fun writeToParcel(dest: Parcel, flags: Int) = with(dest) {
        writeString(yourName)
        writeString(imgPath)
        writeSerializable(calendar)
        writeInt((if (isRead) 1 else 0))
        writeTypedList(items)
    }

    companion object {
        @JvmField
        val CREATOR: Parcelable.Creator<TalkData> = object : Parcelable.Creator<TalkData> {
            override fun createFromParcel(source: Parcel): TalkData = TalkData(source)
            override fun newArray(size: Int): Array<TalkData?> = arrayOfNulls(size)
        }
    }
}