/**
 * Transaction record generator.
 *
 * Produces Transaction records with types, amounts, currencies, and dates
 * spread across 24 months.
 */

import type { SeededRng } from '@/lib/mock-data/seed';
import type { Transaction } from '@/lib/mock-data/types';

const TRANSACTION_TYPES: Transaction['type'][] = ['royalty', 'fee', 'advance', 'adjustment'];

const CURRENCIES = ['USD', 'EUR', 'GBP', 'JPY', 'BRL', 'AUD', 'CAD', 'MXN'] as const;

/**
 * Generate Transaction records.
 *
 * @param rng   - Seeded PRNG instance
 * @param count - Number of transactions to generate (≥300 recommended)
 */
export function generateTransactions(rng: SeededRng, count: number): Transaction[] {
  const transactions: Transaction[] = [];
  const startDate = new Date('2024-01-01');
  const endDate = new Date('2025-12-31');

  for (let i = 0; i < count; i++) {
    const id = `TXN-${String(i + 1).padStart(5, '0')}`;
    const type = rng.pick(TRANSACTION_TYPES);

    // Adjustments can be negative
    let amount = Math.round(rng.randomFloat(50, 15000) * 100) / 100;
    if (type === 'adjustment' && rng.next() < 0.4) {
      amount = -amount;
    }

    transactions.push({
      id,
      type,
      amount,
      currency: rng.pick(CURRENCIES),
      date: rng.randomDate(startDate, endDate),
    });
  }

  return transactions;
}
