//
//  FilterKeywordMO.swift
//  Tusker
//
//  Created by Shadowfacts on 12/2/22.
//  Copyright © 2022 Shadowfacts. All rights reserved.
//

import Foundation
import CoreData
import Pachyderm

@objc(FilterKeywordMO)
public final class FilterKeywordMO: NSManagedObject {
    
    @nonobjc public class func fetchRequest() -> NSFetchRequest<FilterKeywordMO> {
        return NSFetchRequest(entityName: "FilterKeyword")
    }
    
    @NSManaged public var id: String?
    @NSManaged public var keyword: String
    @NSManaged public var wholeWord: Bool
    @NSManaged public var filter: FilterMO
    
}

extension FilterKeywordMO {
    convenience init(apiKeyword keyword: FilterV2.Keyword, context: NSManagedObjectContext) {
        self.init(context: context)
        self.updateFrom(apiKeyword: keyword)
    }
    
    func updateFrom(apiKeyword keyword: FilterV2.Keyword) {
        self.id = keyword.id
        self.keyword = keyword.keyword
        self.wholeWord = keyword.wholeWord
    }
}
