module devtopull;

import std.datetime;
import std.range;

import vibe.data.json;

import devto.api;

/**
 * Provides information about the last execution to pull.
 *
 * This structure will allow retrieving newer articles since the last session.
 */
struct PullState {
    /// When the pull was executed
    SysTime datePulled;
    /// The newest article ID obtained during the pulling
    uint lastArticle;
}

auto isNewerArticle(ArticleMe am, PullState ps) {
    return null;
} unittest {
    import unittesting.articlegenerator;
    import std.algorithm : map, filter;
    PullState ps;
    ps.datePulled = SysTime(DateTime(2018, 1, 1, 10, 30, 0), UTC());
    ps.lastArticle = 10_000;
    auto devreq = generate!fakeArticleMe
        .seqence(ps.datePulled)
        .map!(x => x.deserializeJson!(ArticleMe))
        .take(3);
    assert(devreq.filter!(x => x.isNewerArticle(ps)).empty);
}