/*
 * Copyright (c) 2021 PSMForums. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.joshuacerdenia.android.nicefeed.data.model.entry

import androidx.room.Entity
import androidx.room.PrimaryKey
import java.io.Serializable
import java.util.*

@Entity
data class Entry(
    @PrimaryKey val url: String, // Doubles as URL
    val title: String,
    val website: String,
    val author: String?,
    val date: Date?,
    val content: String?,
    val image: String?,
    var isStarred: Boolean = false,
    var isRead: Boolean = false
) : Serializable {

    // Compare new and existing versions of the same entry, ignoring certain properties
    fun isSameAs(entry: Entry): Boolean {
        val checklist = listOf(
            entry.title == title,
            entry.author == author,
            entry.date == date,
            entry.content == content,
            entry.image == image
        )
        var count = 0
        for (itemChecked in checklist) {
            if (itemChecked) count += 1 else break
        }
        // ALL items must match to return true
        return count == checklist.size
    }
}