/**
 * Mock API data for development/testing when backend isn't available.
 */

export const mockStats = {
  networkId: 'testnet',
  isSynced: true,
  blockCount: 125847,
  headerCount: 125847,
  tipCount: 3,
  virtualDaaScore: 125800,
  difficulty: 1234567890.5,
  hashrate: 45600000000,
  hashrateHuman: '45.60 GH/s',
  blockRate: 9.87,
  mempoolSize: 42,
  peerCount: 24,
  circulatingSupply: 2850000000000000,
  circulatingSupplyHuman: '28,500,000.00000000 SYNOR',
  maxSupply: 21000000000000000,
};

const generateHash = (seed: number) => {
  const chars = '0123456789abcdef';
  let hash = '';
  for (let i = 0; i < 64; i++) {
    hash += chars[(seed * (i + 1) * 17) % 16];
  }
  return hash;
};

export const mockBlocks = Array.from({ length: 25 }, (_, i) => ({
  hash: generateHash(125847 - i),
  version: 1,
  parentHashes: [generateHash(125846 - i)],
  timestamp: Date.now() - i * 100,
  timestampHuman: new Date(Date.now() - i * 100).toISOString(),
  bits: 486604799,
  nonce: Math.floor(Math.random() * 1000000000),
  daaScore: 125800 - i,
  blueScore: 125800 - i,
  blueWork: '0x' + generateHash(i).slice(0, 16),
  difficulty: 1234567890.5,
  transactionCount: Math.floor(Math.random() * 50) + 1,
  isChainBlock: true,
  childrenHashes: i === 0 ? [] : [generateHash(125848 - i)],
  mergeSetBlues: [],
  mergeSetReds: [],
}));

export const mockBlocksResponse = {
  data: mockBlocks,
  page: 1,
  limit: 25,
  total: 125847,
  totalPages: 5034,
  hasNext: true,
  hasPrev: false,
};

export const mockDag = {
  blocks: Array.from({ length: 15 }, (_, i) => ({
    hash: generateHash(125847 - i),
    shortHash: generateHash(125847 - i).slice(0, 8),
    blueScore: 125800 - Math.floor(i / 3),
    isBlue: i % 5 !== 0,
    isChainBlock: i % 3 === 0,
    timestamp: Date.now() - i * 100,
    txCount: Math.floor(Math.random() * 10),
  })),
  edges: Array.from({ length: 14 }, (_, i) => ({
    from: generateHash(125847 - i),
    to: generateHash(125846 - i),
    isSelectedParent: i % 2 === 0,
  })),
};

export const mockTransaction = {
  id: generateHash(999),
  hash: generateHash(999),
  version: 1,
  inputs: [
    {
      previousTxId: generateHash(998),
      previousIndex: 0,
      address: 'synor1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq9test',
      value: 500000000,
    },
  ],
  outputs: [
    {
      value: 450000000,
      valueHuman: '4.50000000 SYNOR',
      scriptType: 'pubkeyhash',
      address: 'synor1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq9recv',
    },
    {
      value: 49900000,
      valueHuman: '0.49900000 SYNOR',
      scriptType: 'pubkeyhash',
      address: 'synor1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq9test',
    },
  ],
  lockTime: 0,
  mass: 1234,
  isCoinbase: false,
  totalInput: 500000000,
  totalOutput: 499900000,
  fee: 100000,
  blockHash: generateHash(125847),
  blockTime: Date.now() - 5000,
};

export const mockAddress = {
  address: 'synor1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq9test',
  balance: 1234500000000,
  balanceHuman: '12,345.00000000 SYNOR',
  utxoCount: 5,
  totalReceived: 50000000000000,
  totalSent: 48765500000000,
  transactionCount: 127,
};

export const mockUtxos = [
  {
    outpoint: { transactionId: generateHash(100), index: 0 },
    utxoEntry: {
      amount: 500000000000,
      scriptPublicKey: { version: 0, script: '76a914...' },
      blockDaaScore: 125700,
      isCoinbase: false,
    },
  },
  {
    outpoint: { transactionId: generateHash(101), index: 1 },
    utxoEntry: {
      amount: 734500000000,
      scriptPublicKey: { version: 0, script: '76a914...' },
      blockDaaScore: 125750,
      isCoinbase: true,
    },
  },
];
