import Foundation

// MARK: - To-do (idea inbox) domain model
// TodoID and TodoStatus moved to NucleicProtocol/CoreIdentifiers.swift (shared with iOS).

/// A quickly-captured idea the user can later "dispatch" as an agent run. Lets the
/// user jot something down (Cmd-T) while other agents are busy, then choose when to
/// start work on it from the home dashboard.
public struct Todo: Identifiable, Sendable, Codable, Equatable {
    public let id: TodoID
    public var text: String
    /// Optional project the idea belongs to; nil = unassigned (chosen at dispatch).
    public var projectID: ProjectID?
    public var status: TodoStatus
    /// The session spawned for this idea once dispatched.
    public var dispatchedSessionID: SessionID?
    /// A short, glanceable summary of `text` for display. `nil` = not yet summarized;
    /// `""` = summarized but no distinct summary (text was already short). `text`
    /// itself stays canonical — it's what gets used as the dispatch prompt.
    public var summary: String?
    /// Stored AI-triage verdict, computed when the idea is added/edited (and whenever
    /// the open set changes) rather than on demand. `nil` = not yet triaged. `level`
    /// drives the row badge; `rank` (0 = most pressing) orders the impact view; `reason`
    /// is the short why, shown on hover. All three are relative to the open set at the
    /// time of the last pass, so they're refreshed together.
    public var triageLevel: TriageLevel?
    public var triageRank: Int?
    public var triageReason: String?
    public let createdAt: Date
    public var updatedAt: Date

    public init(
        id: TodoID = .generate(),
        text: String,
        projectID: ProjectID? = nil,
        status: TodoStatus = .open,
        dispatchedSessionID: SessionID? = nil,
        summary: String? = nil,
        triageLevel: TriageLevel? = nil,
        triageRank: Int? = nil,
        triageReason: String? = nil,
        createdAt: Date,
        updatedAt: Date
    ) {
        self.id = id
        self.text = text
        self.projectID = projectID
        self.status = status
        self.dispatchedSessionID = dispatchedSessionID
        self.summary = summary
        self.triageLevel = triageLevel
        self.triageRank = triageRank
        self.triageReason = triageReason
        self.createdAt = createdAt
        self.updatedAt = updatedAt
    }
}
