package lc.esp.eo;

import com.mongodb.client.MongoCursor;
import lc.esp.eo.sdk.EOAssociation;
import org.bson.Document;

import java.util.Iterator;

public class EOAssociationCursor implements Iterable<EOAssociation>, AutoCloseable {
    private final MongoCursor<Document> cursor;

    public EOAssociationCursor(MongoCursor<Document> cursor) {
        this.cursor = cursor;
    }

    @Override
    public void close() {
        cursor.close();
    }

    @Override
    public Iterator<EOAssociation> iterator() {
        return new Iterator<>() {
            @Override
            public boolean hasNext() {
                return cursor.hasNext();
            }

            @Override
            public EOAssociation next() {
                return EOTransaction.docToAssoc(cursor.next());
            }
        };
    }
}
