package com.iqser.red.service.persistence.management.v1.processor.dataexchange.service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.iqser.red.commons.jackson.ObjectMapperFactory;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.type.Type;

import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
@RequiredArgsConstructor
public class SystemManagedTypesImport {

    private final ObjectMapper objectMapper = ObjectMapperFactory.create();
    private List<Type> rmSystemManagedTypeList = new ArrayList<>();


    @PostConstruct
    public void init() {

        Resource redactManagerResource = new ClassPathResource("files/systemtypes/rm/systemTypes.json");

        try {
            rmSystemManagedTypeList = objectMapper.readValue(redactManagerResource.getContentAsByteArray(), new TypeReference<>() {
            });

        } catch (IOException e) {
            log.info("Could not read the system managed types for  dossier templates error: {}", e.getMessage());
        }
    }


    public List<Type> getSystemManagedTypeList() {

        return this.rmSystemManagedTypeList;
    }

}
