using SharpChat.Events;
using System;
using System.Linq;

namespace SharpChat.Commands {
    public class ActionCommand : IChatCommand {
        public bool IsMatch(ChatCommandContext ctx) {
            return ctx.NameEquals("action")
                || ctx.NameEquals("me");
        }

        public void Dispatch(ChatCommandContext ctx) {
            if(ctx.Args.Length < 1)
                return;

            string actionStr = string.Join(' ', ctx.Args);
            if(string.IsNullOrWhiteSpace(actionStr))
                return;

            ctx.Chat.DispatchEvent(new MessageCreateEvent(
                SharpId.Next(),
                ctx.Channel.Name,
                ctx.User.UserId,
                ctx.User.UserName,
                ctx.User.Colour,
                ctx.User.Rank,
                ctx.User.NickName,
                ctx.User.Permissions,
                DateTimeOffset.Now,
                actionStr,
                false, true, false
            ));
        }
    }
}