import Foundation

public enum ItemSummary: Sendable, Identifiable, Equatable {
	case email(MessageSummary)
	case task(TaskSummary)

	public var id: String {
		switch self {
		case .email(let msg): "email-\(msg.id)"
		case .task(let task): "task-\(task.id)"
		}
	}

	public var title: String {
		switch self {
		case .email(let msg): msg.subject ?? "(no subject)"
		case .task(let task): task.summary
		}
	}

	public var date: Date {
		switch self {
		case .email(let msg): msg.date
		case .task(let task): task.createdAt
		}
	}

	public var dueDate: Date? {
		switch self {
		case .email: nil
		case .task(let task): task.dueDate
		}
	}

	public var isDeferred: Bool {
		switch self {
		case .email: false
		case .task(let task): task.deferUntil != nil
		}
	}

	public var isSomeday: Bool {
		switch self {
		case .email: false
		case .task(let task): task.isSomeday
		}
	}
}
