package ru.ulstu.timeline.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

import static ru.ulstu.core.util.StreamApiUtils.convert;

public class TimelineDto {
    private final Integer id;
    private final List<EventDto> events;

    @JsonCreator
    public TimelineDto(@JsonProperty("id") Integer id,
                       @JsonProperty("events") List<EventDto> events) {
        this.id = id;
        this.events = events;
    }

    public TimelineDto(Timeline timeline) {
        this.id = timeline.getId();
        this.events = convert(timeline.getEvents(), EventDto::new);
    }

    public Integer getId() {
        return id;
    }

    public List<EventDto> getEvents() {
        return events;
    }
}
