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

class RewardLedger {
  constructor({
    actorId,
    sourceService,
    category,
    actionType,
    rewardScore,
    rewardAmount,
    symbol,
    mode,
    refType,
    refId,
    metadata,
    flags,
    blockId,
    blockHeight,
    blockHash,
    minedAt
  } = {}) {
    this.id = uuidv4();
    this.actorId = actorId || null;
    this.sourceService = sourceService || 'UNKNOWN';
    this.category = category || 'ecosystem';
    this.actionType = actionType || 'UNSPECIFIED';
    this.rewardScore = Number(rewardScore || 0);
    this.rewardAmount = Number(rewardAmount || 0);
    this.symbol = symbol || 'AIS';
    this.mode = mode || 'simulation';
    this.refType = refType || null;
    this.refId = refId || null;
    this.metadata = metadata || {};
    this.flags = Array.isArray(flags) ? flags : [];
    this.blockId = blockId || null;
    this.blockHeight = blockHeight || null;
    this.blockHash = blockHash || null;
    this.minedAt = minedAt || null;
    this.createdAt = new Date().toISOString();
  }
}

module.exports = RewardLedger;
