package com.oguerreiro.resilient.service;

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

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

import com.oguerreiro.resilient.domain.VariableScope;
import com.oguerreiro.resilient.repository.VariableScopeRepository;
import com.oguerreiro.resilient.service.dto.VariableScopeDTO;
import com.oguerreiro.resilient.service.mapper.VariableScopeMapper;

/**
 * Service Implementation for managing {@link com.oguerreiro.resilient.domain.VariableScope}.
 */
@Service
@Transactional
public class VariableScopeService extends AbstractResilientService<VariableScopeDTO, VariableScope, Long> {

  private final VariableScopeRepository variableScopeRepository;
  private final VariableScopeMapper variableScopeMapper;

  public VariableScopeService(VariableScopeRepository variableScopeRepository,
      VariableScopeMapper variableScopeMapper) {
    super(VariableScope.class, variableScopeRepository, variableScopeMapper);

    this.variableScopeRepository = variableScopeRepository;
    this.variableScopeMapper = variableScopeMapper;
  }

  @Transactional(readOnly = true)
  public List<VariableScopeDTO> findAllForData() {
    log.debug("Request to get all findAllForData");

    //@formatter:off
    return variableScopeRepository.findByHiddenForDataIsFalseOrHiddenForDataIsNullOrderByCodeAsc()
            .stream() 
            .map(variableScopeMapper::toDto).collect(Collectors.toCollection(LinkedList::new));
    //@formatter:on
  }

  @Transactional(readOnly = true)
  public List<VariableScopeDTO> findAllForFactor() {
    log.debug("Request to get all findAllForFactor");

    //@formatter:off
    return variableScopeRepository.findByHiddenForFactorIsFalseOrHiddenForFactorIsNullOrderByCodeAsc()
            .stream() 
            .map(variableScopeMapper::toDto).collect(Collectors.toCollection(LinkedList::new));
    //@formatter:on
  }
}
