using SharpChat.Events;

namespace SharpChat.ClientCommands {
    public class ActionClientCommand : ClientCommand {
        public bool IsMatch(ClientCommandContext ctx) {
            return ctx.NameEquals("action")
                || ctx.NameEquals("me");
        }

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

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

            ctx.Chat.DispatchEvent(new MessageCreateEvent(
                ctx.Chat.RandomSnowflake.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
            ));
        }
    }
}