const _ = require('lodash');
const common = require('./dynamodb-common');



function _makeParams(self) {
    let params = common.makeParams(self);

    

    return params;
}

function run() {
    let params = _makeParams(this);
    return this._db.scan(params)
        .then(result => {
            if (!_.isNil(result.LastEvaluatedKey)) {
                /**
                 * Add next page method when there is last evaluated key returned
                 */
                result.nextPage = function () {
                    self.exclusiveStartKey(result.LastEvaluatedKey);
                    return self.run();
                }

                result.hasNextPage = function () {
                    return true;
                }
            }
            else {
                result.hasNextPage = function () {
                    return false;
                }
            }

            return result;
        });
}

function dryRun() {
    let params = _makeParams(this);
    // console.log(params);    
    return Promise.resolve(params);    
}

module.exports = {
    run,
    dryRun
}