//
//  FollowedHashtag.swift
//  Tusker
//
//  Created by Shadowfacts on 11/29/22.
//  Copyright © 2022 Shadowfacts. All rights reserved.
//

import Foundation
import CoreData
import Pachyderm
import WebURLFoundationExtras

@objc(FollowedHashtag)
public final class FollowedHashtag: NSManagedObject {
    
    @nonobjc public class func fetchRequest() -> NSFetchRequest<FollowedHashtag> {
        return NSFetchRequest<FollowedHashtag>(entityName: "FollowedHashtag")
    }
    
    @nonobjc public class func fetchRequest(name: String) -> NSFetchRequest<FollowedHashtag> {
        let req = NSFetchRequest<FollowedHashtag>(entityName: "FollowedHashtag")
        req.predicate = NSPredicate(format: "name LIKE[cd] %@", name)
        return req
    }
    
    @NSManaged public var name: String
    @NSManaged public var url: URL
    
}

extension FollowedHashtag {
    convenience init(hashtag: Hashtag, context: NSManagedObjectContext) {
        self.init(context: context)
        self.name = hashtag.name
        self.url = URL(hashtag.url)!
    }
}
