package com.usoftchina.qywx.sdk.dto;

import org.springframework.ui.ModelMap;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author yingp
 */
public class UpdateCalendarReq {
    private String calId;
    private String summary;
    private String color;
    private String description;
    private List<String> shares;

    public UpdateCalendarReq calId(String calId) {
        this.calId = calId;
        return this;
    }

    public UpdateCalendarReq summary(String summary) {
        this.summary = summary;
        return this;
    }

    public UpdateCalendarReq color(String color) {
        this.color = color;
        return this;
    }

    public UpdateCalendarReq description(String description) {
        this.description = description;
        return this;
    }

    public UpdateCalendarReq shares(List<String> shares) {
        this.shares = shares;
        return this;
    }

    public Map<String, Object> build() {
        Map<String, Object> data = new HashMap<>(1);
        Map<String, Object> calendar = new HashMap<>(5);
        calendar.put("cal_id", calId);
        calendar.put("summary", summary);
        calendar.put("color", color);
        if (null != description) {
            calendar.put("description", description);
        }
        if (null != shares) {
            calendar.put("shares",
                    shares.stream().map(attendee -> new ModelMap("userid", attendee)).collect(Collectors.toList())
            );
        }
        data.put("calendar", calendar);
        return data;
    }
}
