package ch.zhaw.gartenverwaltung.types;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.time.LocalDate;

public class TaskTemplate {
    @JsonProperty
    private final String name;
    @JsonProperty
    private final String description;
    @JsonProperty
    private final int relativeStartDate;
    @JsonProperty
    private Integer relativeEndDate;
    @JsonProperty
    private Integer interval;

    // TODO: reconsider if we need this
    @JsonProperty
    private boolean isOptional = false;

    /**
     * Default constructor
     * (Used by deserializer)
     */
    public TaskTemplate() {
        this.name = "";
        this.description = "";
        this.relativeStartDate = 0;
    }

    // Setters
    public void setRelativeEndDate(Integer relativeEndDate) {
        this.relativeEndDate = relativeEndDate;
    }
    public void setInterval(Integer interval) {
        this.interval = interval;
    }

    public TaskTemplate(String name, String description, int relativeStartDate) {
        this.name = name;
        this.description = description;
        this.relativeStartDate = relativeStartDate;
    }

    public Task generateTask(LocalDate realStartDate, long cropId) {
        Task task = new Task(name, description, realStartDate.plusDays(relativeStartDate), cropId);
        if (relativeEndDate != null) {
            task.withEndDate(realStartDate.plusDays(relativeEndDate));
        }
        if (interval != null) {
            task.withInterval(interval);
        }
        return task;
    }
}
