package cn.edu.whu.boot.message.bean;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.concurrent.ConcurrentHashMap;

public class Team {

    private final String teamId;
    private final ConcurrentHashMap<String, Worker> members;

    public int size() {
        return members.size();
    }
    public Team(String teamId, Worker worker) {
        members = new ConcurrentHashMap<>();
        this.teamId = teamId;
        members.put(worker.getName(), worker);
    }

    public Team(String teamId, ConcurrentHashMap<String, Worker> members) {
        this.teamId = teamId;
        this.members = members;
    }

    public ConcurrentHashMap<String, Worker> getMembers() {
        return members;
    }

    public JSONArray teamWorkers() {
        JSONArray result = new JSONArray();
        for (Worker member : members.values()) {
            Position p = member.getPosition();
           if (null != p && !p.isOverdue()) {
               result.add(member);
           }
        }
        return result;
    }

    @Override
    public String toString() {
        return JSONObject.toJSONString(this);
    }
}
