// ─── Dashboard Types ─────────────────────────────────────────────────────────
//
// Data structs for the `lore me` personal dashboard.
// These are populated by query functions and consumed by renderers.

/// Attention state for a work item (AC-4.4).
/// Ordered by display priority (first = most urgent).
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum AttentionState {
    /// Others commented after me (or I never engaged but others have)
    NeedsAttention = 0,
    /// Zero non-system notes from anyone
    NotStarted = 1,
    /// My latest note >= all others' latest notes
    AwaitingResponse = 2,
    /// Latest note from anyone is older than 30 days
    Stale = 3,
    /// MR-only: draft with no reviewers
    NotReady = 4,
}

/// Activity event type for the feed (AC-5.4, AC-6.4).
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ActivityEventType {
    /// Human comment (non-system note)
    Note,
    /// State change (opened/closed/reopened/merged)
    StatusChange,
    /// Label added or removed
    LabelChange,
    /// Assignment event
    Assign,
    /// Unassignment event
    Unassign,
    /// Review request
    ReviewRequest,
    /// Milestone change
    MilestoneChange,
}

/// Summary counts for the dashboard header (AC-5.5).
pub struct MeSummary {
    pub project_count: usize,
    pub open_issue_count: usize,
    pub authored_mr_count: usize,
    pub reviewing_mr_count: usize,
    pub mentioned_in_count: usize,
    pub needs_attention_count: usize,
}

/// An open issue assigned to the user (AC-5.1).
pub struct MeIssue {
    pub iid: i64,
    pub title: String,
    pub project_path: String,
    pub attention_state: AttentionState,
    pub attention_reason: String,
    pub status_name: Option<String>,
    pub labels: Vec<String>,
    pub updated_at: i64,
    pub web_url: Option<String>,
}

/// An open MR authored by or reviewing for the user (AC-5.2, AC-5.3).
pub struct MeMr {
    pub iid: i64,
    pub title: String,
    pub project_path: String,
    pub attention_state: AttentionState,
    pub attention_reason: String,
    pub draft: bool,
    pub detailed_merge_status: Option<String>,
    pub author_username: Option<String>,
    pub labels: Vec<String>,
    pub updated_at: i64,
    pub web_url: Option<String>,
}

/// An activity event in the feed (AC-5.4).
pub struct MeActivityEvent {
    pub timestamp: i64,
    pub event_type: ActivityEventType,
    pub entity_type: String,
    pub entity_iid: i64,
    pub project_path: String,
    pub actor: Option<String>,
    pub is_own: bool,
    pub summary: String,
    pub body_preview: Option<String>,
}

/// A single actionable event in the "since last check" section.
#[derive(Clone)]
pub struct SinceCheckEvent {
    pub timestamp: i64,
    pub event_type: ActivityEventType,
    pub actor: Option<String>,
    pub summary: String,
    pub body_preview: Option<String>,
}

/// Events grouped by entity for the "since last check" section.
#[derive(Clone)]
pub struct SinceCheckGroup {
    pub entity_type: String,
    pub entity_iid: i64,
    pub entity_title: String,
    pub project_path: String,
    pub events: Vec<SinceCheckEvent>,
    pub latest_timestamp: i64,
}

/// The complete "since last check" result.
pub struct SinceLastCheck {
    pub cursor_ms: i64,
    pub groups: Vec<SinceCheckGroup>,
    pub total_event_count: usize,
}

/// An issue or MR where the user is @mentioned but not formally associated.
pub struct MeMention {
    /// "issue" or "mr"
    pub entity_type: String,
    pub iid: i64,
    pub title: String,
    pub project_path: String,
    /// "opened", "closed", or "merged"
    pub state: String,
    pub attention_state: AttentionState,
    pub attention_reason: String,
    pub updated_at: i64,
    pub web_url: Option<String>,
}

/// The complete dashboard result.
pub struct MeDashboard {
    pub username: String,
    pub since_ms: Option<i64>,
    pub summary: MeSummary,
    pub open_issues: Vec<MeIssue>,
    pub open_mrs_authored: Vec<MeMr>,
    pub reviewing_mrs: Vec<MeMr>,
    pub mentioned_in: Vec<MeMention>,
    pub activity: Vec<MeActivityEvent>,
    pub since_last_check: Option<SinceLastCheck>,
}
