use crate::{layout::Rect, state::TaskStatus, AgentMode, FlowLane, PaneId, Rgba, ThinkingMode};

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct PaneChrome {
    pub id: PaneId,
    pub title: String,
    pub subtitle: String,
    pub rect: Rect,
    pub focused: bool,
}

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct TranscriptItem {
    pub role: String,
    pub content: String,
    pub detail: String,
}

impl TranscriptItem {
    pub fn system(content: impl Into<String>) -> Self {
        Self {
            role: "system".to_string(),
            content: content.into(),
            detail: String::new(),
        }
    }

    pub fn user(content: impl Into<String>) -> Self {
        Self {
            role: "user".to_string(),
            content: content.into(),
            detail: "local prompt".to_string(),
        }
    }

    pub fn assistant(content: impl Into<String>, detail: impl Into<String>) -> Self {
        Self {
            role: "assistant".to_string(),
            content: content.into(),
            detail: detail.into(),
        }
    }
}

#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct PromptModel {
    pub mode: AgentMode,
    pub thinking: ThinkingMode,
    pub input: String,
    pub cursor: usize,
    pub placeholder: String,
}

impl PromptModel {
    pub fn label(&self) -> String {
        format!(
            "{} think:{}",
            self.mode.prompt_prefix(),
            self.thinking.label()
        )
    }
}

#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct StatusChip {
    pub label: String,
    pub value: String,
    pub color: Rgba,
}

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct KanbanColumn {
    pub status: TaskStatus,
    pub cards: Vec<String>,
}

#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct DeckModel {
    pub active_lane: FlowLane,
    pub chips: Vec<StatusChip>,
    pub columns: Vec<KanbanColumn>,
    pub recommendations: Vec<String>,
}

#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct WidgetFrame {
    pub panes: Vec<PaneChrome>,
    pub prompt: PromptModel,
    pub transcript: Vec<TranscriptItem>,
    pub deck: DeckModel,
}
