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(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);
    }

}
