package cz.senslog.connector.fetch.demo;

import cz.senslog.connector.fetch.api.ConnectorFetchProvider;
import cz.senslog.connector.fetch.api.ConnectorFetcher;
import cz.senslog.connector.fetch.api.ExecutableFetcher;
import cz.senslog.connector.model.api.AbstractModel;
import cz.senslog.connector.model.api.ProxySessionModel;
import cz.senslog.connector.model.config.DefaultConfig;
import cz.senslog.connector.model.demo.DemoModel;

import java.time.OffsetDateTime;
import java.util.Optional;

public class ConnectorFetchDemoProvider implements ConnectorFetchProvider  {

    @Override
    public ExecutableFetcher<DemoModel> createExecutableFetcher(DefaultConfig defaultConfig) {
        return ExecutableFetcher.create(new ConnectorFetcher<ProxySessionModel, DemoModel>() {

            private int executionRun;

            @Override
            public void init() throws Exception {
                this.executionRun = 0;
            }

            @Override
            public DemoModel fetch(Optional<ProxySessionModel> session) {
                OffsetDateTime now = OffsetDateTime.now();
                return new DemoModel("Execution run: " + (++executionRun), now, now);
            }
        });
    }
}
