

const {api} =require("../api/prisma");
const _ =require("lodash");
const { omit } = require("lodash");

async function setAttendanceManagement(){
     var entry = {
        key:'at',
        config:{
            databaseCollection:{
                code_function:null,
                users:null,
                departements:null,
                dispositifs:null,
                work_times:null, // horaire de travaile, grille horaire
                models:null,
                planning:null
            },
            link:'/apps/at/scope',
            logo:'at.png',
            active:false,
            label:'Attendance Management',
            description:`Attendance Management is an application used to monitor the attendance based on fingerprints or faciale facial recognition `
        }
    }
    // attendance management
    // key: at
    var response = await api.findFirst("marketplaces_local",{
        where:{
            key:'at'
        }
    }).catch(err=>null).then(e=>e)
    if(!response?.id) {
        await api.createOne("marketplaces_local",{
            data:entry
        }).catch(err=>{
            console.error(err)
        })
    } else {
        let data = _.merge(_.omit(response,['id']),_.omit(entry,['config.active']))
        await api.updateOne("marketplaces_local",{
            where:{
                id:response.id
            },
            data:data
        })
    }

}




async function syncApps(api){

await setAttendanceManagement()

}


module.exports={
    setAttendanceManagement,
    syncApps
}