use serde_json::Value;
use crate::error::EmbedError;
use crate::handoff::BoxFuture;
use crate::types::{LingaraEvent, PlanSummary, Reaction};
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct Plan {
pub summary: PlanSummary,
pub status: String,
pub sets: Vec<PlanSet>,
}
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct PlanSet {
pub number: u8,
pub questions: Vec<Question>,
}
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct Question {
pub kind: String,
pub prompt: String,
pub options: Option<Vec<String>>,
pub answer: String,
pub explanation: String,
pub hint: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct Accepted {
pub event_id: String,
pub reaction: Option<Reaction>,
}
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum PlanFrame {
Started(String),
Result(Box<Plan>),
Pending,
Other,
}
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum TurnFrame {
Delta(String),
Notice { code: String, message: String },
Transition { edge: String, to: String },
Other,
}
pub(crate) trait Frames<T>: Send {
fn next(&mut self) -> BoxFuture<'_, Option<Result<T, EmbedError>>>;
}
pub(crate) trait Tail: Send {
fn next(&mut self) -> BoxFuture<'_, Option<Result<LingaraEvent, EmbedError>>>;
fn cursor(&self) -> Option<String>;
}
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum Exported {
Body { rev: u64, etag: String, ir_json: String },
NotModified { rev: u64, etag: String },
}
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum PlanAnswer {
Planned { fragment: Value },
Kept { reason: String },
}
pub(crate) type PlanStream = Box<dyn Frames<PlanFrame>>;
pub(crate) type TurnStream = Box<dyn Frames<TurnFrame>>;
pub(crate) trait Api: Send + Sync + 'static {
fn tail(&self, cursor: Option<String>, types: Vec<String>) -> Box<dyn Tail>;
fn send_event(&self, body: Value, key: String) -> BoxFuture<'_, Result<Accepted, EmbedError>>;
fn get_plan(&self, id: String) -> BoxFuture<'_, Result<Plan, EmbedError>>;
fn create_plan(&self, body: Value) -> BoxFuture<'_, Result<PlanStream, EmbedError>>;
fn stream_plan(&self, id: String) -> BoxFuture<'_, Result<PlanStream, EmbedError>>;
fn dialogue_turn(&self, body: Value) -> BoxFuture<'_, Result<TurnStream, EmbedError>>;
fn export_dialogue(&self, dialogue_id: String, if_none_match: Option<String>) -> BoxFuture<'_, Result<Exported, EmbedError>>;
fn plan_dialogue(&self, body: Value) -> BoxFuture<'_, Result<PlanAnswer, EmbedError>>;
}