#include "Server.hpp"
#include "Message.hpp"

int
Server::_cmdNOTICE(Message const& msg)
{
    if (msg.getArgs().size() < 2) {
        return 0;
    }

    Client& client = msg.getClient();

    std::list<Client>::iterator it;
    for (it = _clients.begin(); it != _clients.end(); ++it) {
        if (it->nick == msg.getArgs()[0]) {
            if (it->sendMsg(client.nick, "NOTICE " + it->nick, msg.getArgs()[1])
                    && it->nick == client.nick) {
                return 1;
            }
            return 0;
        }
    }
    for (size_t i = 0; i < _channels.size(); ++i) {
        if (_channels[i].getName() == msg.getArgs()[0]) {
            _channels[i].sendNotice(msg.getArgs()[1], client);
            return 0;
        }
    }
    return 0;
}
