const { signStatement } = require('./signatures');


function makeStatement(publisherId, namespace, statementBody, counter = 0, timestampGenerator = Date.now) {
  const timestamp = timestampGenerator();
  const statementId = [publisherId.id58, timestamp.toString(), counter.toString()].join(':');
  const stmt = {
    id: statementId,
    publisher: publisherId.id58,
    namespace,
    timestamp,
    body: statementBody,
    signature: Buffer.from('')
  };
  return signStatement(stmt, publisherId);
}

function makeSimpleStatement(publisherId, namespace, contents, counter = 0, timestampGenerator = Date.now) {
  const { object, refs, deps, tags } = Object.assign({ object: '', refs: [], deps: [], tags: [] }, contents);
  const body = { object, refs, deps, tags };
  return makeStatement(publisherId, namespace, { simple: body }, counter, timestampGenerator);
}

module.exports = {
  makeStatement,
  makeSimpleStatement
};