use poise::{serenity_prelude::CreateEmbed, CreateReply};
use serde::{Deserialize, Serialize};

use crate::{
    consts::THEME_COLOR,
    models::CtxData,
    utils::{Extract, Recordable},
    Context, Error,
};

#[derive(Serialize, Deserialize, Extract)]
pub struct Options;

impl Recordable for Options {
    async fn run(self, ctx: Context<'_>) -> Result<(), Error> {
        let mut guild_data = ctx.guild_data().await.unwrap()?;
        guild_data.ephemeral_confirmations = false;
        guild_data.commit_changes(&ctx.data().database).await;

        ctx.send(
            CreateReply::default().ephemeral(true).embed(
                CreateEmbed::new()
                    .title("Confirmations public")
                    .description(concat!(
                        "Reminder and todo confirmations will be sent as regular messages, and",
                        " won't be removed automatically."
                    ))
                    .color(*THEME_COLOR),
            ),
        )
        .await?;

        Ok(())
    }
}

/// Set reminder confirmations to persist indefinitely
#[poise::command(
    slash_command,
    rename = "off",
    identifying_name = "unset_ephemeral_confirmations",
    guild_only = true
)]
pub async fn unset(ctx: Context<'_>) -> Result<(), Error> {
    (Options {}).run(ctx).await
}
