package cn.axzo.msg.center.message.service.todo.manage.event;

import cn.axzo.msg.center.domain.entity.Todo;
import cn.axzo.msg.center.service.pending.request.TodoHandoverRequest;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;

import java.util.HashMap;
import java.util.List;

/**
 * @author yanglin
 */
@Getter
public class HandoverEvent extends ApplicationEvent {

    private final TodoHandoverRequest request;
    private final List<Todo> srcTodos;
    private final List<Todo> destTodos;

    public HandoverEvent(TodoHandoverRequest request,
                         List<Todo> srcTodos, List<Todo> destTodos) {
        super(request);
        this.request = request;
        this.srcTodos = srcTodos;
        this.destTodos = destTodos;
    }

    public int todoCount() {
        return srcTodos.size();
    }

    @Override
    public String toString() {
        HashMap<String, Object> fields = new HashMap<>();
        fields.put("request", request);
        fields.put("srcTodos", srcTodos);
        fields.put("destTodos", destTodos);
        fields.put("todoCount", todoCount());
        return JSON.toJSONString(fields);
    }

}