package com.usoftchina.qywx.sdk.dto;

import java.util.*;

/**
 * @author yingp
 */
public class CreateChatReq {
    /**
     * 群聊名，最多50个utf8字符，超过将截断
     */
    private String name;
    /**
     * 指定群主的id。如果不指定，系统会随机从userlist中选一人作为群主
     */
    private String owner;
    /**
     * 群成员id列表。至少2人，至多500人
     */
    private Set<String> userSet;
    /**
     * 群聊的唯一标志，不能与已有的群重复；字符串类型，最长32个字符。只允许字符0-9及字母a-zA-Z。如果不填，系统会随机生成群id
     */
    private String chatId;

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

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

    public CreateChatReq chatId(String chatId) {
        this.chatId = chatId;
        return this;
    }

    public CreateChatReq user(String... userId) {
        if(null == userSet) {
            userSet = new HashSet<>(1);
        }
        userSet.addAll(Arrays.asList(userId));
        return this;
    }

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