package com.usoftchina.qywx.sdk.dto;

import java.util.*;

/**
 * @author yingp
 */
public class UpdateChatReq {
    private String chatId;
    /**
     * 新的群聊名。若不需更新，请忽略此参数。最多50个utf8字符，超过将截断
     */
    private String name;
    /**
     * 新群主的id。若不需更新，请忽略此参数
     */
    private String owner;
    /**
     * 添加成员的id列表
     */
    private Set<String> addUserSet;
    /**
     * 踢出成员的id列表
     */
    private Set<String> delUserSet;

    public UpdateChatReq(String chatId) {
        this.chatId = chatId;
    }

    public UpdateChatReq name(String name) {
        this.name = name;
        return this;
    }

    public UpdateChatReq owner(String owner) {
        this.owner = owner;
        return this;
    }

    public UpdateChatReq addUser(String... userId) {
        if (null == addUserSet) {
            addUserSet = new HashSet<>(1);
        }
        addUserSet.addAll(Arrays.asList(userId));
        return this;
    }

    public UpdateChatReq delUser(String... userId) {
        if (null == delUserSet) {
            delUserSet = new HashSet<>(1);
        }
        delUserSet.addAll(Arrays.asList(userId));
        return this;
    }

    public Map<String, Object> build() {
        Map<String, Object> data = new HashMap<>(4);
        data.put("chatid", chatId);
        if (null != name) {
            data.put("name", name);
        }
        if (null != owner) {
            data.put("owner", owner);
        }
        if (null != addUserSet) {
            data.put("add_user_list", addUserSet);
        }
        if (null != delUserSet) {
            data.put("del_user_list", delUserSet);
        }
        return data;
    }
}
