import Foundation

/// One thing the alien might come on screen to tell you about.
struct Reminder {
    enum Kind {
        case meeting

        /// Small all-caps line above the title in the speech bubble.
        var eyebrow: String {
            switch self {
            case .meeting: return "INCOMING TRANSMISSION"
            }
        }
    }

    let id: String
    let kind: Kind
    let title: String
    let due: Date

    /// Whole minutes from now until `due`, floored at 0.
    var minutesAway: Int {
        max(0, Int((due.timeIntervalSinceNow / 60).rounded()))
    }

    /// The line the alien actually says.
    var spokenLine: String {
        let mins = minutesAway
        switch kind {
        case .meeting:
            if mins <= 0 { return "\(title) — starting now." }
            if mins == 1 { return "\(title) in 1 minute." }
            return "\(title) in \(mins) minutes."
        }
    }

    /// Fired-once key. Includes the due minute so a rescheduled item can fire again.
    var dedupeKey: String {
        "\(id)@\(Int(due.timeIntervalSince1970 / 60))"
    }
}
