package com.ecep.contract.service;

import com.ecep.contract.CustomerFileType;
import com.ecep.contract.model.CompanyCustomerFileTypeLocal;
import com.ecep.contract.vm.CompanyCustomerFileTypeLocalViewModel;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

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

@Service
@CacheConfig(cacheNames = "company-file-type")
public class CompanyCustomerFileTypeService extends QueryService<CompanyCustomerFileTypeLocal, CompanyCustomerFileTypeLocalViewModel>{
    @Cacheable
    public Map<CustomerFileType, CompanyCustomerFileTypeLocal> findAll(Locale locale) {
        Map<String, Object> params = new HashMap<>();
        params.put("lang", locale.toLanguageTag());
        return findAll(params, Pageable.unpaged()).stream()
                .collect(Collectors.toMap(CompanyCustomerFileTypeLocal::getType, Function.identity()));
    }
}
