//! The type that represents a composition object.
//!
//! <https://api.slack.com/reference/block-kit/composition-objects>

use crate::ButtonStyle;
use serde::Serialize;

/// The type that represents a text object.
///
/// Defines an object containing some text.
///
/// <https://api.slack.com/reference/block-kit/composition-objects#text>
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case", tag = "type")]
pub enum TextObject {
    /// The `plain_text`.
    PlainText(PlainTextObject),

    /// The `mrkdwn`.
    #[serde(rename = "mrkdwn")]
    Markdown(MarkdownTextObject),
}

/// A type that represents `plain_text` in [`TextObject`].
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct PlainTextObject {
    /// The text for the block.
    pub text: String,

    /// Indicates whether emojis in a text field should be escaped into the colon emoji format.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub emoji: Option<bool>,
}

/// A type that represents `mrkdwn` in [`TextObject`].
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct MarkdownTextObject {
    /// The text for the block.
    pub text: String,

    /// When set to `false` (as is default) URLs will be auto-converted into links, conversation names will be link-ified, and certain mentions will be [automatically parsed](https://api.slack.com/reference/surfaces/formatting#automatic-parsing).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub verbatim: Option<bool>,
}

/// The type that represents a confirmation dialog object.
///
/// Defines a dialog that adds a confirmation step to interactive elements.
///
/// <https://api.slack.com/reference/block-kit/composition-objects#confirm>
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct ConfirmObect {
    /// A plain_text text object that defines the dialog's title.
    pub title: PlainTextObject,

    /// A plain_text text object that defines the explanatory text that appears in the confirm dialog.
    pub text: TextObject,

    /// A plain_text text object to define the text of the button that confirms the action.
    pub confirm: PlainTextObject,

    /// A plain_text text object to define the text of the button that cancels the action.
    pub deny: PlainTextObject,

    /// Defines the color scheme applied to the confirm button.
    #[serde(skip_serializing_if = "ButtonStyle::is_default")]
    pub style: ButtonStyle,
}

// TODO: not implemented.
// #[derive(Serialize, Debug, Clone)]
// #[serde(rename_all = "snake_case")]
// pub struct OptionObject;
//
// #[derive(Serialize, Debug, Clone)]
// #[serde(rename_all = "snake_case")]
// pub struct OptionGroupObject;
