package ru.ulstu.timeline.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import ru.ulstu.user.model.UserDto;

import java.util.Date;
import java.util.List;

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

public class EventDto {
    private final Integer id;
    private final String title;
    private final Event.EventStatus status;
    private final Date executeDate;
    private final Date createDate;
    private final Date updateDate;
    private final String description;
    private final List<UserDto> recipients;

    @JsonCreator
    public EventDto(@JsonProperty("id") Integer id,
                    @JsonProperty("title") String title,
                    @JsonProperty("status") Event.EventStatus status,
                    @JsonProperty("executeDate") Date executeDate,
                    @JsonProperty("createDate") Date createDate,
                    @JsonProperty("updateDate") Date updateDate,
                    @JsonProperty("description") String description,
                    @JsonProperty("recipients") List<UserDto> recipients) {
        this.id = id;
        this.title = title;
        this.status = status;
        this.executeDate = executeDate;
        this.createDate = createDate;
        this.updateDate = updateDate;
        this.description = description;
        this.recipients = recipients;
    }

    public EventDto(Event event) {
        this.id = event.getId();
        this.title = event.getTitle();
        this.status = event.getStatus();
        this.executeDate = event.getExecuteDate();
        this.createDate = event.getCreateDate();
        this.updateDate = event.getUpdateDate();
        this.description = event.getDescription();
        this.recipients = convert(event.getRecipients(), UserDto::new);
    }

    public Integer getId() {
        return id;
    }

    public String getTitle() {
        return title;
    }

    public Event.EventStatus getStatus() { return status; }

    public Date getCreateDate() {
        return createDate;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public String getDescription() {
        return description;
    }

    public List<UserDto> getRecipients() {
        return recipients;
    }

    public Date getExecuteDate() {
        return executeDate;
    }
}
