import Foundation
import SwiftData

@Model
final class CelestiaTimelineEvent {
    var id: UUID
    var relativeTimeMs: Int64
    var eventType: String  // NOTE, PHOTO, MARKER, VOICE
    var textContent: String?
    var localFilePath: String?
    var voiceStartOffsetMs: Int64?
    var voiceEndOffsetMs: Int64?
    var createdAt: Date
    
    var session: CelestiaSession?
    
    var relativeTimeFormatted: String {
        let totalSeconds = Int(relativeTimeMs / 1000)
        let hours = totalSeconds / 3600
        let minutes = (totalSeconds % 3600) / 60
        let seconds = totalSeconds % 60
        if hours > 0 {
            return String(format: "%d:%02d:%02d", hours, minutes, seconds)
        }
        return String(format: "%02d:%02d", minutes, seconds)
    }
    
    var eventIcon: String {
        switch eventType {
        case "PHOTO": return "camera.fill"
        case "NOTE": return "note.text"
        case "MARKER": return "exclamationmark.triangle.fill"
        case "VOICE": return "mic.fill"
        default: return "circle.fill"
        }
    }
    
    init(id: UUID = UUID(), relativeTimeMs: Int64, eventType: String) {
        self.id = id
        self.relativeTimeMs = relativeTimeMs
        self.eventType = eventType
        self.createdAt = Date()
    }
}
