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

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;

import lombok.SneakyThrows;

@Service
public class DefaultDateFormatsProvider {

    private String dateFormats;


    @SneakyThrows
    public String getDateFormats() {

        if (dateFormats == null) {
            Resource resource = new ClassPathResource("files/dateFormats.txt");
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8))) {
                dateFormats = reader.lines()
                        .collect(Collectors.joining(System.lineSeparator()));
            }
        }

        return dateFormats;
    }

}

