package xyz.r0r5chach.dermy.entities.logs;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

public class LogBook {
    private final List<LogEntry> logEntries;

    public LogBook() {
        logEntries = new ArrayList<>();
    }

    public void addEntry(LogEntry entry) {
        logEntries.add(entry);
    } //TODO: Add to db

    //TODO: Remove Entry

    //TODO: Update Entry

    private LogBook getEntriesBy(Object obj) {
        LogBook results = new LogBook();

        for (LogEntry entry: logEntries) {
            if (entry.getDateCreated().equals(obj) || entry.getNotes().contains((CharSequence) obj)) {
                results.addEntry(entry);
            }
            else {
                return null;
            }
        }
        return results;
    }

    public LogBook getEntriesByDate(LocalDateTime dateCreated) {
        return getEntriesBy(dateCreated);
    }

    public LogBook getEntriesByNote(String noteFragment) {
        return getEntriesBy(noteFragment);
    }
}
