import { defineStore } from 'pinia'
import { useLocalStorage } from '@vueuse/core'

export const useStatsStore = defineStore('stats', () => {
  const stats = useLocalStorage('ddac-stats', {
    ccAttacks: 19009,
    ddosPeak: 22844,
    wafBlocks: 56870
  })

  const incrementStats = () => {
    stats.value.ccAttacks += Math.floor(Math.random() * 151) + 50
    stats.value.ddosPeak += Math.floor(Math.random() * 151) + 50
    stats.value.wafBlocks += Math.floor(Math.random() * 151) + 50
  }

  const startAutoIncrement = () => {
    return setInterval(incrementStats, 2000)
  }

  const stopAutoIncrement = (intervalId) => {
    clearInterval(intervalId)
  }

  return {
    stats,
    startAutoIncrement,
    stopAutoIncrement
  }
})
