TheNoiseClock/TheNoiseClock/Models/Alarm.swift

64 lines
1.7 KiB
Swift

//
// Alarm.swift
// TheNoiseClock
//
// Created by Matt Bruce on 9/7/25.
//
import Foundation
/// Alarm data model
struct Alarm: Identifiable, Codable, Equatable {
let id: UUID
var time: Date
var isEnabled: Bool
var soundName: String
var label: String
var notificationMessage: String // Custom notification message
var snoozeDuration: Int // in minutes
var isVibrationEnabled: Bool
var isLightFlashEnabled: Bool
var volume: Float
// MARK: - Initialization
init(
id: UUID = UUID(),
time: Date,
isEnabled: Bool = true,
soundName: String = AppConstants.SystemSounds.defaultSound,
label: String = "Alarm",
notificationMessage: String = "Your alarm is ringing",
snoozeDuration: Int = 9,
isVibrationEnabled: Bool = true,
isLightFlashEnabled: Bool = false,
volume: Float = 1.0
) {
self.id = id
self.time = time
self.isEnabled = isEnabled
self.soundName = soundName
self.label = label
self.notificationMessage = notificationMessage
self.snoozeDuration = snoozeDuration
self.isVibrationEnabled = isVibrationEnabled
self.isLightFlashEnabled = isLightFlashEnabled
self.volume = volume
}
// MARK: - Equatable
static func ==(lhs: Alarm, rhs: Alarm) -> Bool {
lhs.id == rhs.id
}
// MARK: - Helper Methods
func nextTriggerTime() -> Date {
return time.nextOccurrence()
}
func formattedTime() -> String {
let formatter = DateFormatter()
formatter.timeStyle = .short
return formatter.string(from: time)
}
}