
const {api} = require("../api/prisma")
const {database} =require('../mongo-connector')

async function Initialize(config){

    // Initialize the Public Role
     let rolePublic = await api.findMany('Roles',{
        where:{
          name:{
            equals:'public',
            mode:'insensitive'
          }
        }
      }).then(e=>e)
      .catch(err=>[])

      var init ={
        rolePublic: rolePublic||[]
      }

      config.init = {
        ...config.init,
        ...init
      }

}


function WatchInitialize(config){
  database.collection("Roles").watch().on("change",(ev)=>{
    Initialize(config)
  })
}


module.exports={
    Initialize,
    WatchInitialize
}