//
//  HistoryItem.swift
//  App
//
//  Created by James Magahern on 8/14/20.
//

import CoreData
import Foundation

struct HistoryItem: Hashable, Identifiable
{
    var url: URL
    var title: String
    var lastVisited: Date
    var id: NSManagedObjectID
    
    init(entity: HistoryItemEntity) {
        self.url = entity.url ?? URL(string: "about:blank")!
        self.lastVisited = entity.lastVisited ?? Date()
        self.title = entity.title ?? ""
        self.id = entity.objectID
    }
    
    // For testing/previews
    public init(url: URL, title: String, lastVisited: Date) {
        self.url = url
        self.title = title
        self.lastVisited = lastVisited
        self.id = NSManagedObjectID()
    }
}
