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.PermissionGroupDatabaseType;
030import com.github.theholywaffle.teamspeak3.commands.parameter.KeyValueParam;
031import com.github.theholywaffle.teamspeak3.commands.parameter.OptionParam;
032
033public final class ServerGroupCommands {
034
035        private ServerGroupCommands() {
036                throw new Error("No instances");
037        }
038
039        public static Command serverGroupAdd(String groupName, PermissionGroupDatabaseType type) {
040                if (groupName == null || groupName.isEmpty()) {
041                        throw new IllegalArgumentException("Server group name must be a non-empty string");
042                }
043
044                CommandBuilder builder = new CommandBuilder("servergroupadd", 2);
045                builder.add(new KeyValueParam("name", groupName));
046                if (type != null) {
047                        builder.add(new KeyValueParam("type", type.getIndex()));
048                }
049                return builder.build();
050        }
051
052        public static Command serverGroupAddClient(int groupId, int clientDBId) {
053                CommandBuilder builder = new CommandBuilder("servergroupaddclient", 2);
054                builder.add(new KeyValueParam("sgid", groupId));
055                builder.add(new KeyValueParam("cldbid", clientDBId));
056                return builder.build();
057        }
058
059        public static Command serverGroupClientList(int groupId) {
060                CommandBuilder builder = new CommandBuilder("servergroupclientlist", 2);
061                builder.add(new KeyValueParam("sgid", groupId));
062                builder.add(new OptionParam("names"));
063                return builder.build();
064        }
065
066        public static Command serverGroupCopy(int sourceGroupId, int targetGroupId, PermissionGroupDatabaseType type) {
067                return serverGroupCopy(sourceGroupId, targetGroupId, "name", type);
068        }
069
070        public static Command serverGroupCopy(int sourceGroupId, String groupName, PermissionGroupDatabaseType type) {
071                return serverGroupCopy(sourceGroupId, 0, groupName, type);
072        }
073
074        private static Command serverGroupCopy(int sourceGroupId, int targetGroupId, String groupName, PermissionGroupDatabaseType type) {
075                if (type == null) {
076                        throw new IllegalArgumentException("Group type cannot be null");
077                }
078                if (groupName == null || groupName.isEmpty()) {
079                        throw new IllegalArgumentException("Server group name must be a non-empty string");
080                }
081
082                CommandBuilder builder = new CommandBuilder("servergroupcopy", 4);
083                builder.add(new KeyValueParam("ssgid", sourceGroupId));
084                builder.add(new KeyValueParam("tsgid", targetGroupId));
085                builder.add(new KeyValueParam("name", groupName));
086                builder.add(new KeyValueParam("type", type.getIndex()));
087                return builder.build();
088        }
089
090        public static Command serverGroupDel(int id, boolean force) {
091                CommandBuilder builder = new CommandBuilder("servergroupdel", 2);
092                builder.add(new KeyValueParam("sgid", id));
093                builder.add(new KeyValueParam("force", force));
094                return builder.build();
095        }
096
097        public static Command serverGroupDelClient(int groupId, int clientDBId) {
098                CommandBuilder builder = new CommandBuilder("servergroupdelclient", 2);
099                builder.add(new KeyValueParam("sgid", groupId));
100                builder.add(new KeyValueParam("cldbid", clientDBId));
101                return builder.build();
102        }
103
104        public static Command serverGroupList() {
105                return new CommandBuilder("servergrouplist").build();
106        }
107
108        public static Command serverGroupRename(int id, String groupName) {
109                if (groupName == null || groupName.isEmpty()) {
110                        throw new IllegalArgumentException("Server group name must be a non-empty string");
111                }
112
113                CommandBuilder builder = new CommandBuilder("servergrouprename", 2);
114                builder.add(new KeyValueParam("sgid", id));
115                builder.add(new KeyValueParam("name", groupName));
116                return builder.build();
117        }
118
119        public static Command serverGroupsByClientId(int clientDBId) {
120                return new CommandBuilder("servergroupsbyclientid", 1).add(new KeyValueParam("cldbid", clientDBId)).build();
121        }
122}