// Общее хранилище кликов для всех API роутов
class ClickStorage {
  private static instance: ClickStorage
  private storage = new Map<string, number>()

  static getInstance(): ClickStorage {
    if (!ClickStorage.instance) {
      ClickStorage.instance = new ClickStorage()
    }
    return ClickStorage.instance
  }

  recordClick(linkId: string): number {
    const currentClicks = this.storage.get(linkId) || 0
    const newClicks = currentClicks + 1
    this.storage.set(linkId, newClicks)
    console.warn(`Click recorded for ${linkId}: ${newClicks} total`)
    return newClicks
  }

  getClicks(linkId: string): number {
    return this.storage.get(linkId) || 0
  }

  getAllClicks(): Record<string, number> {
    return Object.fromEntries(this.storage)
  }
}

export const clickStorage = ClickStorage.getInstance()
