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

class NodeEconomyLedger {
  constructor({
    nodeId,
    userId,
    sourceService,
    eventType,
    amount,
    balanceLocked,
    balanceReward,
    balanceSlashed,
    reason,
    refType,
    refId,
    transactionId,
    txHash,
    metadata
  } = {}) {
    this.id = uuidv4();
    this.nodeId = nodeId || null;
    this.userId = userId || null;
    this.sourceService = sourceService || 'AISFOR_CHAIN';
    this.eventType = eventType || 'NODE_ECONOMY_EVENT';
    this.amount = Number(amount || 0);
    this.balanceLocked = Number(balanceLocked || 0);
    this.balanceReward = Number(balanceReward || 0);
    this.balanceSlashed = Number(balanceSlashed || 0);
    this.reason = reason || '';
    this.refType = refType || null;
    this.refId = refId || null;
    this.transactionId = transactionId || null;
    this.txHash = txHash || null;
    this.metadata = metadata || {};
    this.createdAt = new Date().toISOString();
  }
}

module.exports = NodeEconomyLedger;
