package ru.ulstu.timeline.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.hibernate.validator.constraints.NotBlank;
import ru.ulstu.user.model.UserDto;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;

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

public class EventDto {
    private final Integer id;
    @NotBlank
    private final String title;
    private final PeriodEvent period;
    private final Event.EventStatus status;
    @NotNull
    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("period") PeriodEvent period,
                    @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.period = period;
        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.period = event.getPeriod();
        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 PeriodEvent getPeriod() {
        return period;
    }

    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;
    }
}
