package com.sldlt.downloader.dto;

import java.time.LocalDate;
import java.time.LocalDateTime;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.sldlt.downloader.TaskStatus;

public class TaskDto implements Comparable<TaskDto> {

    private Long id;

    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate dateFrom;

    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate dateTo;

    private String fund;

    private String fundName;

    private TaskStatus status;

    private int attempts = 0;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime nextAttemptAfter;

    private boolean retryable = true;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public LocalDate getDateFrom() {
        return dateFrom;
    }

    public void setDateFrom(LocalDate dateFrom) {
        this.dateFrom = dateFrom;
    }

    public LocalDate getDateTo() {
        return dateTo;
    }

    public void setDateTo(LocalDate dateTo) {
        this.dateTo = dateTo;
    }

    public String getFund() {
        return fund;
    }

    public void setFund(String fund) {
        this.fund = fund;
    }

    public String getFundName() {
        return fundName;
    }

    public void setFundName(String fundName) {
        this.fundName = fundName;
    }

    public TaskStatus getStatus() {
        return status;
    }

    public void setStatus(TaskStatus status) {
        this.status = status;
    }

    public int getAttempts() {
        return attempts;
    }

    public void setAttempts(int attempts) {
        this.attempts = attempts;
    }

    public LocalDateTime getNextAttemptAfter() {
        return nextAttemptAfter;
    }

    public void setNextAttemptAfter(LocalDateTime nextAttemptAfter) {
        this.nextAttemptAfter = nextAttemptAfter;
    }

    public boolean isRetryable() {
        return retryable;
    }

    public void setRetryable(boolean retryable) {
        this.retryable = retryable;
    }

    @Override
    public String toString() {
        return "Task - " + fund + " - " + this.id + " " + this.dateTo.toString() + " -> " + this.dateFrom.toString();
    }

    @Override
    public int compareTo(TaskDto task) {
        if (id == task.getId()) {
            return 0;
        }
        if (id > task.getId()) {
            return 1;
        } else {
            return -1;
        }
    }

}

@@ -87,16 +87,43 @@
 ateTime;
+%0Aimport java.util.Optional;
 %0A%0Aimport
@@ -2300,30 +2300,209 @@
     
-if (id == task.getId()
+long ownId = Optional.ofNullable(id).map(Long::longValue).orElse(0L);%0A        long otherId = Optional.ofNullable(task).map(TaskDto::getId).map(Long::longValue).orElse(0L);%0A%0A        if (ownId == otherId
 ) %7B%0A
@@ -2549,25 +2549,23 @@
 if (
-id %3E task.getId()
+ownId %3E otherId
 ) %7B%0A

fix comparison warning