import type { FastifyInstance } from "fastify"
import mongoose from "mongoose"
import registerRoutes from "./routes"
import { createCollectionService } from "./collections.service"

const registerSystem = (fastify: FastifyInstance) => {
  registerRoutes(fastify)

  // create and pass in the model to your service
  const collectionService = createCollectionService(mongoose.connection)

  // decorate the service to the instance, so we can easily call it everywhere
  fastify.core.collectionService = collectionService
}

export default registerSystem
