package io.delphiplatform.api.v3.rdb.service.ads;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

import io.delphiplatform.api.v3.decibelrdb.repository.DecibelCampaignObjectiveEntityRepository;
import io.delphiplatform.api.v3.model.ads.Objective;

@Service
public class DecibelCampaignObjectiveService {

    private final DecibelCampaignObjectiveEntityRepository repository;

    public DecibelCampaignObjectiveService(
        DecibelCampaignObjectiveEntityRepository repository) {
        this.repository = repository;
    }

    @Transactional(readOnly = true)
    public List<Objective> findAllById(List<Integer> ids) {
        return repository.findAllById(ids).stream()
            .map(Objective::from)
            .collect(Collectors.toList());
    }

    @Transactional(readOnly = true)
    public List<Objective> findAllByName(List<String> names) {
        return repository.findAllByNameIn(names).stream()
            .map(Objective::from)
            .collect(Collectors.toList());
    }

}
