import axios from 'axios'

const urlBase = "http://127.0.0.1:5000/"
//const urlBase = "http://193.70.2.155:5000/"
const users = "utilisateurs/"
const contenus = "contenus/"
const en_cours = "en_cours/"
const demande_pub = "demande_pub/"
//const evaluation = "evaluation/




export default {

    getHeader(token){
        return   {headers:
                {
                    Authorization: "Bearer " + token,
                }
        }
    },

    // gestion des utilisateurs
    login(data) {
        let login = data[0]
        let motDePasse = data[1]
        /*      let reponse = ""
              axios.get(urlBase + "checkUser?login=" + login + "&password=" + motDePasse).then(function (response) {
                   reponse =  response.data
              })*/
        return axios.get(urlBase + users + "checkUser?login=" + login + "&password=" + motDePasse, this.getHeader(localStorage.token))
    },
    // gestion des utilisateurs
/*    logout() {
        return axios.get(urlBase + users + "logout", this.getHeader(localStorage.token))
    },*/
    recupererAuteursExistants(){
        return axios.get(urlBase + users + "auteursExistants", this.getHeader(localStorage.token))
    },

    // gestion des contenus

    creerContenuPerso(data) {
        return axios.post(urlBase + contenus + "addContenu", data, this.getHeader(localStorage.token))
    },
    uploaderContenuPerso(data, auteur){
        return axios.post(urlBase + contenus + "uploadContenu/" + auteur, data, {
            headers: {
                'Content-Type': 'multipart/form-data',
                Authorization: "Bearer " + localStorage.token,
            }
        })
    },
    creerContenuTiers(data) {
        return axios.patch(urlBase + contenus + "ajouterTiers", data, this.getHeader(localStorage.token))
    },
    /*    getContenuById(idContenu) {
            return axios.get(urlBase + contenus + "getContenu/" + idContenu)
        },*/

    getPanierAuteur(auteur) {
        return axios.get(urlBase + contenus + "getContenuPanier/" + auteur + "?perso=True&tiers=True&enCours=true", this.getHeader(localStorage.token))
    },

    getBanqueAuteur(auteur) {
        return axios.get(urlBase + contenus + "getContenuBanque/" + auteur, this.getHeader(localStorage.token))
    },
    supprimerContenu(idContenu) {
        return axios.delete(urlBase + contenus + "deletePerso/" + idContenu, this.getHeader(localStorage.token))
    },

    supprimerTiers(auteur, id_tiers, note) {
        return axios.delete(urlBase + contenus + "deleteTiers?auteur=" + auteur + "&id_tiers=" + id_tiers + "&note=" + note, this.getHeader(localStorage.token))
    },

    creerNouveauContenu(data) {
        return axios.post(urlBase + contenus + "newContenu", data, this.getHeader(localStorage.token))
    },

    majContenu(data) {
        return axios.patch(urlBase + contenus + "majContenu", data, this.getHeader(localStorage.token))

    },    gererDemandePublication(data) {
        return axios.patch(urlBase + contenus + "gererDemandePub", data, this.getHeader(localStorage.token))
    },
    isMajTiersDisponible(auteur) {
        return axios.get(urlBase + contenus + "isMajTiersDisponible/" + auteur, this.getHeader(localStorage.token))
    },
    listeMajTiers(auteur) {
        return axios.get(urlBase + contenus + "listeMajTiers/" + auteur, this.getHeader(localStorage.token))
    },
    gererMajTiers(data) {
        return axios.patch(urlBase + contenus + "gererMajTiers", data, this.getHeader(localStorage.token))
    },
    changerTexte(data, id) {
        return axios.patch(urlBase + contenus + "changerTexte/" + id, data, this.getHeader(localStorage.token))
    },
    recupererTexteContenu(idContenu){
        return axios.get(urlBase + contenus + "getTexteContenu/" + idContenu, this.getHeader(localStorage.token))
    },
    recupererTexteVersionContenu(idContenu, version){
        return axios.get(urlBase + contenus + "getTexteVersionContenu/" + idContenu + "/" + version, this.getHeader(localStorage.token))
    },
    incrementerPopularite(data){
        return axios.patch(urlBase + contenus + "incrementerPopularite", data, this.getHeader(localStorage.token))
    },
    noterContenu(data){
        return axios.patch(urlBase + contenus + "noterContenu", data, this.getHeader(localStorage.token))
    },
    recupererNoteContenu(idContenu, auteur, version){
        return axios.get(urlBase + contenus + "recupererNote?auteur=" + auteur + "&version=" + version + "&id_contenu=" + idContenu, this.getHeader(localStorage.token))
    },
    // gestion des contenus - fonctions spéciales tags
    ajouterTagLibre(data){
        return axios.patch(urlBase + contenus + "newTagLibre", data, this.getHeader(localStorage.token))
    },
    recupererTagLibre(auteur){
        return axios.get(urlBase + contenus + "getTagLibre/" + auteur, this.getHeader(localStorage.token))
    },
    recupererTagLibreContenu(idContenu, auteur){
        return axios.get(urlBase + contenus + "getTagLibreContenu/" + idContenu + "/" + auteur, this.getHeader(localStorage.token))
    },
    associerTagLibre(data){
        return axios.patch(urlBase + contenus + "associerTagLibre", data, this.getHeader(localStorage.token))
    },
    dissocierTagLibre(data){
        return axios.patch(urlBase + contenus + "dissocierTagLibre", data, this.getHeader(localStorage.token))
    },
    supprimerTagLibre(auteur, tag){
        return axios.delete(urlBase + contenus + "supprimerTagLibre?auteur=" + auteur + "&tag=" + tag, this.getHeader(localStorage.token))
    },
    modifierTagsFixes(data) {
        return axios.patch(urlBase + contenus + "modifierTags", data, this.getHeader(localStorage.token))
    },
    // gestion des en-cours
    creerEnCours(data) {
        return axios.post(urlBase + en_cours + "newEnCours", data, this.getHeader(localStorage.token))
    },

    creerEnCoursRefuse(data) {
        return axios.patch(urlBase + en_cours + "newEnCoursRefuse", data, this.getHeader(localStorage.token))
    },
    supprimerEnCoursParLid(idEnCours) {
        return axios.delete(urlBase + en_cours + "supprimerEnCoursParId/" + idEnCours, this.getHeader(localStorage.token))
    },
    recupererTexteContenuEnCours(idContenu){
        return axios.get(urlBase + en_cours + "getTexteContenuEnCours/" + idContenu, this.getHeader(localStorage.token))
    },


    // gestion des demandes de publication

    getPublicationsRecues(auteur) {
        return axios.get(urlBase + demande_pub + "demandePublication/" + auteur + "/False", this.getHeader(localStorage.token))
    },

    getPublicationsProposees(auteur) {
        return axios.get(urlBase + demande_pub + "demandePublication/" + auteur + "/True", this.getHeader(localStorage.token))
    },

    creerDemandePublication(data) {
        return axios.post(urlBase + demande_pub + "demandePublication", data, this.getHeader(localStorage.token))

    },
    supprimerDemandePublication(idDemandePublication) {
        return axios.delete(urlBase + demande_pub + "demandePublication/" + idDemandePublication, this.getHeader(localStorage.token))
    }

}