//
//  CDPreview.swift
//  Zockerhoehle
//
//  Created by Julian-Steffen Müller on 25.05.21.
//  Copyright © 2021 Julian-Steffen Müller. All rights reserved.
//

import Foundation
import CoreData
import UIKit

struct CDPreview {
    static let shared : CDPreview = CDPreview()
    
    private init() {
        let asset_core_data = NSDataAsset(name: "CoreDataSample", bundle: Bundle.main)

        guard let data = asset_core_data?.data else { return }

        LibraryImport(context: CDManager.preview.viewContextPreview).importLIB(data: data)
    }
    
    func consoles() -> [Console] {
        let consolesFR = NSFetchRequest<Console>(entityName: "Console")
        do {
            let consoles : [Console] = try CDManager.preview.viewContextPreview.fetch(consolesFR)
            
            return consoles
        }catch {
            return []
        }
    }
    
}
