import fp from 'fastify-plugin'
import { createStorageProvider, type StorageProvider } from '../storage/index.js'

declare module 'fastify' {
  interface FastifyInstance {
    storage: StorageProvider
  }
}

export const storagePlugin = fp(async (app) => {
  const storage = createStorageProvider()
  app.decorate('storage', storage)
  app.log.info(`Storage provider: ${process.env.STORAGE_PROVIDER ?? 'local'}`)
})
