package com.fractalite.amad_ndc.services;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;

@Component
public class CrmEndpoints {
    private HashMap<Integer, String> urls = new HashMap<>();
    private Logger LOG = LoggerFactory.getLogger(this.getClass());

    public CrmEndpoints() {
        this.urls.put(0, "http://crmapi.reedmackay.tourcom.biz/api");
        this.urls.put(1, "http://crmapi.cta.tourcom.biz/api");
        this.urls.put(2, "http://crmapi.gallia.tourcom.biz/api");
        this.urls.put(3, "http://crmapi.impact.tourcom.biz/api");
        this.urls.put(4, "http://metisapi.fractal-sales.com/api");
        this.urls.put(5, "http://crmapi.agences.tourcom.biz/api");
        this.urls.put(6, "http://crmapi.feeling.tourcom.biz/api");
        this.urls.put(7, "https://crm.sotlamer.com/api");
        this.urls.put(8, "http://univairmerapi.fractal-sales.com/api");
        this.urls.put(9, "http://crmapi.atlasvoyages.com/api");
        //this.urls.put(9, "http://crmtest-api.fractal-sales.com/api");
        this.urls.put(11, "http://kti.fractal-sales.com/api");
        this.urls.put(12, "http://crmtest-api.fractal-sales.com/api");

    }

//    public CrmEndpoints() {
//        try {
//            ObjectMapper mapper = new ObjectMapper();
//
//            List<Endpoints> endpoints = mapper.readValue(new File(System.getProperty("user.dir") + "/" +  "agences-crm-apis.json"),
//                    new TypeReference<List<Endpoints>>() {
//                    });
//
////            List<Endpoints> endpoints = mapper.readValue(new File("src/main/resources/agences-crm-apis.json"),
////                    new TypeReference<List<Endpoints>>() {
////                    });
//            for (Endpoints endpoint : endpoints) {
//                this.urls.put(endpoint.getId(), endpoint.getHref());
//            }
//            LOG.info("Crm End points loaded successfully");
//        } catch (IOException e) {
//            LOG.error("FAILED loading Crm End points");
//            e.printStackTrace();
//        }
//
//    }

    public String getCrmEndpoint(int code) {
        return this.urls.get(code);
    }

}
