require('dotenv').config();
module.exports = {


    friendlyName: 'Delete',


    description: 'Delete admin.',


    inputs: {
        /* id:{
           type:'number',
           required: true
         },*/
        anneeScolaire: {
            type: 'string',
            require: true
        },

        logiUsername: {
            type: 'string',
            require: true

        },
        key: {
            type: 'string',
            require: true

        },
        logiPassword: {
            type: 'string',
            require: true

        },
    },


    exits: {
        notFound: {
            description: "Not found"
        }
    },


    fn: async function (inputs, exits) {

        // TOKEN VERIFY
        let user = await Utilisateurs.find({ login: inputs.logiUsername, codeUser: inputs.logiPassword }).then(_.first)

        if (!user) {
            return exits.notFound('Utilisateur non trouvé')
        }
        console.log("INPUTS 2", inputs)

        let keyVerify = process.env.KEYVERIFY
        //
        if (keyVerify !== inputs.key) {
            return exits.notFound({ message: "Token non valide" })
        }


        ///////////////////

        let annne = await AnneeScolaire.find({ anneeScolaire: inputs.anneeScolaire }).then(_.first)
        if (!annne) {
            return exits.notFound({ message: "Année Scolaire non retrouvée!" })
        }

        /*let userSection = await User.find({section: inputs.id}).then(_.first)
        if(userSection){
          return exits.notFound({message:"Suppression impossible car cette section est rattachée à un Prestataire actuellement!"})
        }*/

        let anneeDestroy = await AnneeScolaire.destroy({ id: annne.id }).fetch();

        // All done.
        return exits.success({ message: 'Done !' })

    }


};
