//
//  StoryVideoExtension.swift
//  WoWonder
//
//  Created by iMac on 25/09/23.
//  Copyright © 2023 ScriptSun. All rights reserved.
//

import Foundation

extension StoryVideo: CoreDataObject {
    
    convenience init(storyVideo: StoryVideoModel) {
        self.init(context: CoreDataManager.getInstance().context)
        self.id = storyVideo.id
        self.story_id = storyVideo.storyID
        self.type = storyVideo.type
        self.filename = storyVideo.filename
        self.expire = storyVideo.expire
    }
    
    func save() {
        self.setValue(story_id, forKey: #keyPath(StoryVideo.story_id))
        self.setValue(type, forKey: #keyPath(StoryVideo.type))
        self.setValue(filename, forKey: #keyPath(StoryVideo.filename))
        self.setValue(expire, forKey: #keyPath(StoryVideo.expire))
        
        do {
            try self.managedObjectContext!.save()
            
        } catch let err {
            print("ERROR \(#file) => \(#function) => \(err.localizedDescription)")
        }
    }
}
