import Foundation

// MARK: - Shared Content Models

struct SharedMediaItem: Identifiable {
    let attachmentId: String
    let messageId: String
    let senderName: String
    let timestamp: Int64
    let caption: String
    let blurhash: String
    var id: String { attachmentId }
}

struct SharedFileItem: Identifiable {
    let attachmentId: String
    let messageId: String
    let fileName: String
    let fileSize: Int
    let preview: String
    let timestamp: Int64
    let senderName: String
    var id: String { attachmentId }

    var formattedDate: String {
        let date = Date(timeIntervalSince1970: Double(timestamp) / 1000.0)
        let formatter = DateFormatter()
        formatter.dateFormat = "MMM d, yyyy"
        return formatter.string(from: date)
    }

    var formattedSize: String {
        if fileSize <= 0 { return "" }
        if fileSize < 1024 { return "\(fileSize) B" }
        if fileSize < 1024 * 1024 { return String(format: "%.1f KB", Double(fileSize) / 1024.0) }
        return String(format: "%.1f MB", Double(fileSize) / (1024.0 * 1024.0))
    }

    var subtitle: String {
        let parts = [formattedSize, formattedDate].filter { !$0.isEmpty }
        return parts.joined(separator: " · ")
    }
}

struct SharedLinkItem: Identifiable {
    let url: String
    let messageId: String
    let context: String
    let timestamp: Int64
    let senderName: String
    var id: String { "\(messageId)_\(url)" }

    var displayHost: String {
        URL(string: url)?.host ?? url
    }
}
