package com.ecep.contract.service;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.ecep.contract.ContractFileType;
import com.ecep.contract.model.ContractFileTypeLocal;
import com.ecep.contract.vm.ContractFileTypeLocalViewModel;

@Service
@CacheConfig(cacheNames = "contract-file-type")
public class ContractFileTypeService extends QueryService<ContractFileTypeLocal, ContractFileTypeLocalViewModel> {

    @Cacheable
    public Map<ContractFileType, ContractFileTypeLocal> findAll(Locale locale) {
        Map<String, Object> params = new HashMap<>();
        params.put("lang", locale.toLanguageTag());
        return findAll(params, Pageable.unpaged()).stream()
                .collect(Collectors.toMap(ContractFileTypeLocal::getType, Function.identity()));
    }

}
