// taskManagerTypes.ts

export interface TaskOptions {
  // Base options for all tasks
  errorHandler?: (error: Error) => void
}

export interface IntervalTaskOptions extends TaskOptions {
  // Interval in seconds
  seconds: number

  // Whether to run the task immediately when created
  runImmediately?: boolean

  // Whether this task should keep running even when no WebSocket connections
  keepRunning?: boolean
}

// Extend FastifyInstance to include our task manager
declare module "fastify" {
  export interface FastifyInstance {
    taskManager: {
      createIntervalTask: (
        name: string,
        handler: () => Promise<void>,
        options: IntervalTaskOptions,
      ) => void
      cancelTask: (name: string) => void
      markAppReady: () => void
      stopAllTasks: () => void
      getTaskCount: () => number
    }
  }
}
