001package com.github.theholywaffle.teamspeak3.commands;
002
003/*
004 * #%L
005 * TeamSpeak 3 Java API
006 * %%
007 * Copyright (C) 2017 Bert De Geyter, Roger Baumgartner
008 * %%
009 * Permission is hereby granted, free of charge, to any person obtaining a copy
010 * of this software and associated documentation files (the "Software"), to deal
011 * in the Software without restriction, including without limitation the rights
012 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
013 * copies of the Software, and to permit persons to whom the Software is
014 * furnished to do so, subject to the following conditions:
015 * 
016 * The above copyright notice and this permission notice shall be included in
017 * all copies or substantial portions of the Software.
018 * 
019 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
020 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
021 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
022 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
023 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
024 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
025 * THE SOFTWARE.
026 * #L%
027 */
028
029import com.github.theholywaffle.teamspeak3.api.ChannelProperty;
030import com.github.theholywaffle.teamspeak3.commands.parameter.KeyValueParam;
031import com.github.theholywaffle.teamspeak3.commands.parameter.OptionParam;
032
033import java.util.Map;
034
035public final class ChannelCommands {
036
037        private ChannelCommands() {
038                throw new Error("No instances");
039        }
040
041        public static Command channelCreate(String name, Map<ChannelProperty, String> options) {
042                if (name == null || name.isEmpty()) {
043                        throw new IllegalArgumentException("Channel name must be a non-empty string");
044                }
045
046                CommandBuilder builder = new CommandBuilder("channelcreate", 2);
047                builder.add(new KeyValueParam("channel_name", name));
048                builder.addProperties(options);
049                return builder.build();
050        }
051
052        public static Command channelDelete(int channelId, boolean force) {
053                CommandBuilder builder = new CommandBuilder("channeldelete", 2);
054                builder.add(new KeyValueParam("cid", channelId));
055                builder.add(new KeyValueParam("force", force));
056                return builder.build();
057        }
058
059        public static Command channelEdit(int channelId, Map<ChannelProperty, String> options) {
060                CommandBuilder builder = new CommandBuilder("channeledit", 2);
061                builder.add(new KeyValueParam("cid", channelId));
062                builder.addProperties(options);
063                return builder.build();
064        }
065
066        public static Command channelFind(String pattern) {
067                if (pattern == null || pattern.isEmpty()) {
068                        throw new IllegalArgumentException("Channel name pattern must be a non-empty string");
069                }
070
071                return new CommandBuilder("channelfind", 1).add(new KeyValueParam("pattern", pattern)).build();
072        }
073
074        public static Command channelInfo(int channelId) {
075                return new CommandBuilder("channelinfo", 1).add(new KeyValueParam("cid", channelId)).build();
076        }
077
078        public static Command channelList() {
079                CommandBuilder builder = new CommandBuilder("channellist", 7);
080                builder.add(new OptionParam("topic"));
081                builder.add(new OptionParam("flags"));
082                builder.add(new OptionParam("voice"));
083                builder.add(new OptionParam("limits"));
084                builder.add(new OptionParam("icon"));
085                builder.add(new OptionParam("secondsempty"));
086                builder.add(new OptionParam("banners"));
087                return builder.build();
088        }
089
090        public static Command channelMove(int channelId, int channelParentId, int order) {
091                CommandBuilder builder = new CommandBuilder("channelmove", 3);
092                builder.add(new KeyValueParam("cid", channelId));
093                builder.add(new KeyValueParam("cpid", channelParentId));
094                builder.add(new KeyValueParam("order", order < 0 ? 0 : order));
095                return builder.build();
096        }
097}