package com.gh.gamecenter.feature.entity

import android.os.Parcel
import android.os.Parcelable
import com.google.gson.annotations.SerializedName

/**
 * Created by khy on 2017/4/18.
 */
class MessageEntity {

    @SerializedName(value = "_id", alternate = ["message_id"])
    var id: String = ""

    var time: Long = 0

    var article: Article = Article()

    var comment: Comment = Comment()

    var dialogue: Dialogue = Dialogue()

    var question: Question = Question()

    var answer: Answer = Answer()

    @SerializedName("game_list")
    var gameList: GameList = GameList()

    var type: String = ""

    var read: Boolean = true // true:已读,false:未读

    @SerializedName("user")
    var userEntity: UserEntity = UserEntity()

    var game: SimpleGame = SimpleGame()

    var video: Video = Video()

    var reply: Reply = Reply()

    var fold: Fold? = null

    var activity: Activity = Activity()

    val source: SourceEntity? = null

    class Article() : Parcelable {
        @SerializedName("_id")
        var id: String? = null

        var title: String? = null

        var thumb: String? = null

        @SerializedName("community_id")
        var communityId: String? = null

        var images: List<String> = ArrayList()

        var videos: List<Video> = ArrayList()

        constructor(parcel: Parcel) : this() {
            id = parcel.readString()
            title = parcel.readString()
            thumb = parcel.readString()
            communityId = parcel.readString()
            images = parcel.createStringArrayList() ?: arrayListOf()
            parcel.readTypedList(videos, Video)
        }

        override fun writeToParcel(parcel: Parcel, flags: Int) {
            parcel.writeString(id)
            parcel.writeString(title)
            parcel.writeString(thumb)
            parcel.writeString(communityId)
            parcel.writeStringList(images)
            parcel.writeTypedList(videos)
        }

        override fun describeContents(): Int {
            return 0
        }

        companion object {
            const val TAG = "Article"

            @JvmField
            val CREATOR: Parcelable.Creator<Article> = object : Parcelable.Creator<Article> {
                override fun createFromParcel(parcel: Parcel): Article {
                    return Article(parcel)
                }

                override fun newArray(size: Int): Array<Article?> {
                    return arrayOfNulls(size)
                }
            }
        }
    }

    class Answer() : Parcelable {
        @SerializedName("_id")
        var id: String? = null

        var content: String? = null

        var images: List<String> = ArrayList()

        constructor(parcel: Parcel) : this() {
            id = parcel.readString()
            content = parcel.readString()
            images = parcel.createStringArrayList() ?: arrayListOf()
        }

        override fun writeToParcel(parcel: Parcel, flags: Int) {
            parcel.writeString(id)
            parcel.writeString(content)
            parcel.writeStringList(images)
        }

        override fun describeContents(): Int {
            return 0
        }


        companion object {
            const val TAG = "MessageAnswer"

            @JvmField
            val CREATOR: Parcelable.Creator<Answer> = object : Parcelable.Creator<Answer> {
                override fun createFromParcel(parcel: Parcel): Answer {
                    return Answer(parcel)
                }

                override fun newArray(size: Int): Array<Answer?> {
                    return arrayOfNulls(size)
                }
            }
        }
    }

    class Question {
        @SerializedName("_id")
        var id: String? = null

        var title: String? = null

        var images: List<String> = ArrayList()

        var videos: List<Video> = ArrayList()
    }


    class Dialogue {

        var from: From = From()

        var to: To = To()
    }

    class From {
        @SerializedName("_id")
        var id: String? = null

        var content: String? = null
    }

    class To {
        @SerializedName("_id")
        var id: String? = null

        @SerializedName("top_id")
        var topId: String? = null

        var content: String? = null

        var images: List<String> = ArrayList()

        var type: String? = null // 取值 reply/comment，代表父内容是回复/评论
    }

    class Comment {
        @SerializedName("_id")
        var id: String? = null

        @SerializedName("top_id", alternate = ["parent_id"])
        var topId: String? = null

        var content: String? = null

        var parent: Parent = Parent()

        var images: List<String> = ArrayList()
    }

    class Parent {
        @SerializedName("_id")
        var id: String = ""

        var content: String = ""

        var type: String = ""

        var images: List<String> = ArrayList()
    }

    class Video() : Parcelable {
        @SerializedName("_id")
        var id: String? = null

        var title: String? = null

        var poster: String? = null

        constructor(parcel: Parcel) : this() {
            id = parcel.readString()
            title = parcel.readString()
            poster = parcel.readString()
        }

        override fun writeToParcel(parcel: Parcel, flags: Int) {
            parcel.writeString(id)
            parcel.writeString(title)
            parcel.writeString(poster)
        }

        override fun describeContents(): Int {
            return 0
        }

        companion object CREATOR : Parcelable.Creator<Video> {
            override fun createFromParcel(parcel: Parcel): Video {
                return Video(parcel)
            }

            override fun newArray(size: Int): Array<Video?> {
                return arrayOfNulls(size)
            }
        }
    }

    class Fold {
        @SerializedName("resource_id")
        var resourceId: String = ""

        var number: Int = 0
    }

    class Reply {
        @SerializedName("_id")
        var id: String? = null

        var content: String? = null

        @SerializedName("comment_id")
        var commentId: String? = null

        var comment: String? = null

        var parent: Parent = Parent()

        var images: List<String> = ArrayList()
    }

    class Activity {
        @SerializedName("_id")
        var id: String? = null
        var title: String? = null

        @SerializedName("image_url")
        var imageUrl: String? = null

        var url: String? = null

        @SerializedName("url_comment")
        var urlComment: String? = null
    }

    class GameList {
        @SerializedName("_id")
        var id: String = ""
        var cover: String = ""
        var title: String = ""
    }

}
