//
//  Model+SharedExtensions.swift
//  LeCountdown
//
//  Created by Laurent Morvillier on 17/02/2023.
//

import Foundation

extension AbstractTimer {
    
    var displayName: String {
        return self.name ?? self.coolpic.emoji
    }
    
    var name: String? {
        return self.activity?.name
    }
    
    var url: URL {
        if let url = URL(string: self.stringId) {
            return url
        } else {
            fatalError("Can't produce url with \(self.stringId)")
        }
    }
    
    var coolpic: CoolPic {
        if let image, let coolpic = CoolPic(rawValue: image) {
            return coolpic
        }
        return CoolPic.allCases[0]
    }
    
    var imageName: String {
        return self.coolpic.rawValue
    }

}
