//
//  Shortcut.swift
//  LeCountdown
//
//  Created by Laurent Morvillier on 22/02/2023.
//

import Foundation
import UIKit
import CoreServices
import CoreSpotlight
import UniformTypeIdentifiers

enum Shortcut: String {
    
    case newCountdown = "app.kikai.NewCountdown"
    
    var userActivity: NSUserActivity {
        let activity = NSUserActivity(activityType: self.rawValue)
        activity.persistentIdentifier = NSUserActivityPersistentIdentifier(self.rawValue)
        
        activity.title = self.title
        activity.suggestedInvocationPhrase = self.suggestedInvocationPhrase
        activity.isEligibleForSearch = true
        activity.isEligibleForPrediction = true
        
        let attributes = CSSearchableItemAttributeSet(contentType: UTType.item)
        attributes.contentDescription = self.contentDescription
        attributes.thumbnailData = self.image?.jpegData(compressionQuality: 1.0)
        activity.contentAttributeSet = attributes
        return activity
    }
    
    var title: String {
        switch self {
        case .newCountdown: return NSLocalizedString("New countdown", comment: "")
        }
    }
    
    var suggestedInvocationPhrase: String {
        switch self {
        case .newCountdown: return NSLocalizedString("Create countdown", comment: "")
        }
    }
    
    var contentDescription: String {
        switch self {
        case .newCountdown: return NSLocalizedString("Create a new countdown", comment: "")
        }
    }
    
    var image: UIImage? {
        return UIImage(named: "pic1")
    }
        
}
