use serenity;

use super::super::prelude::*;

use serenity::prelude::*;
use serenity::{
    framework::standard::{macros::command, Args, CommandResult},
    model::channel::Message,
};

#[command]
fn pause(ctx: &mut Context, msg: &Message, _: Args) -> CommandResult {
    if let Err(err) = channel_contains_author(ctx, msg) {
        msg.channel_id.say(&ctx.http, err)?;
        return Ok(());
    }

    let data = ctx.data.read();
    let media = match data.get::<Media>() {
        Some(media) => media,
        None => {
            msg.channel_id.say(&ctx.http, "could not find media data")?;
            return Ok(());
        }
    };

    let media_lock = media.lock().unwrap();

    if let Some(song) = media_lock.song() {
        let mut lock = song.lock();
        lock.pause();
    }

    Ok(())
}
