package com.pixelized.biblib.database.data

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import java.util.*

@Entity(tableName = BookDbo.TABLE)
data class BookDbo(
    @PrimaryKey
    @ColumnInfo(name = ID)
    val id: Int,
    @ColumnInfo(name = TITLE)
    val title: String,
    @ColumnInfo(name = SORT)
    val sort: String,
    @ColumnInfo(name = HAVE_COVER)
    val haveCover: Boolean,
    @ColumnInfo(name = RELEASE_DATE)
    val releaseDate: Date,
    @ColumnInfo(name = LANGUAGE_ID)
    val language: Int? = null,       // one-to-many
    @ColumnInfo(name = RATING)
    val rating: Int? = null,
    // details
    @ColumnInfo(name = SERIES_ID)
    val series: Int? = null,            // one-to-many
    @ColumnInfo(name = SERIES_INDEX)
    val seriesIndex: Int? = null,
    @ColumnInfo(name = SYNOPSIS)
    val synopsis: String? = null,
    // source
    @ColumnInfo(name = IS_NEW)
    val isNew: Boolean = false,
    @ColumnInfo(name = NEW_ORDER)
    val newOrder: Int? = null,
) {
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other !is BookDbo) return false
        if (id != other.id) return false
        return true
    }

    override fun hashCode(): Int {
        return id
    }

    companion object {
        const val TABLE = "BOOK"
        const val ID = "${TABLE}_ID"
        const val TITLE = "${TABLE}_TITLE"
        const val SORT = "${TABLE}_SORT"
        const val HAVE_COVER = "${TABLE}_HAVE_COVER"
        const val RELEASE_DATE = "${TABLE}_RELEASE_DATE"
        const val LANGUAGE_ID = "${TABLE}_LANGUAGE_ID"
        const val RATING = "${TABLE}_RATING"
        const val SERIES_ID = "${TABLE}_SERIES_ID"
        const val SERIES_INDEX = "${TABLE}_SERIES_INDEX"
        const val SYNOPSIS = "${TABLE}_SYNOPSIS"
        const val IS_NEW = "${TABLE}_IS_NEW"
        const val NEW_ORDER = "${TABLE}_NEW_ORDER"
    }
}