const { v4: uuidv4 } = require('uuid');

class CallbackEvent {
  constructor({
    sourceService,
    callbackType,
    blockId,
    blockHeight,
    blockHash,
    proofId,
    transactionId,
    targetUrl,
    payload
  } = {}) {
    this.id = uuidv4();
    this.sourceService = sourceService || 'UNKNOWN';
    this.callbackType = callbackType || 'BLOCK_FINALIZED';
    this.blockId = blockId || null;
    this.blockHeight = blockHeight || null;
    this.blockHash = blockHash || null;
    this.proofId = proofId || null;
    this.transactionId = transactionId || null;
    this.targetUrl = targetUrl || null;
    this.payload = payload || {};
    this.status = targetUrl ? 'PENDING' : 'MOCK_DELIVERED';
    this.attempts = 0;
    this.lastStatusCode = null;
    this.lastError = null;
    this.createdAt = new Date().toISOString();
    this.updatedAt = this.createdAt;
    this.deliveredAt = targetUrl ? null : this.createdAt;
  }
}

module.exports = CallbackEvent;
