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.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.oguerreiro.resilient.domain.InputDataUpload;
import com.oguerreiro.resilient.domain.InputDataUploadLog;
import com.oguerreiro.resilient.repository.InputDataUploadLogRepository;
import com.oguerreiro.resilient.service.dto.InputDataUploadLogDTO;
import com.oguerreiro.resilient.service.mapper.InputDataUploadLogMapper;

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

  private final InputDataUploadLogRepository inputDataUploadLogRepository;

  private final InputDataUploadLogMapper inputDataUploadLogMapper;

  public InputDataUploadLogService(InputDataUploadLogRepository inputDataUploadLogRepository,
      InputDataUploadLogMapper inputDataUploadLogMapper) {
    super(InputDataUploadLog.class, inputDataUploadLogRepository, inputDataUploadLogMapper);
    this.inputDataUploadLogRepository = inputDataUploadLogRepository;
    this.inputDataUploadLogMapper = inputDataUploadLogMapper;
  }

  /**
   * Get all the inputDataUploadLogs by owner.
   *
   * @return the list of entities.
   */
  @Transactional(readOnly = true)
  public List<InputDataUploadLogDTO> findAllByOwner(Long id) {
    log.debug("Request to get all InputDataUploadLogs by owner : {}", id);
    return inputDataUploadLogRepository.findAllByInputDataUploadId(id).stream().map(
        inputDataUploadLogMapper::toDto).collect(Collectors.toCollection(LinkedList::new));
  }

  @Transactional(propagation = Propagation.REQUIRES_NEW)
  public void deleteAllByInputDataUploadWithNewTransaction(InputDataUpload inputDataUpload) {
    this.deleteAllByInputDataUpload(inputDataUpload);
  }

  public void deleteAllByInputDataUpload(InputDataUpload inputDataUpload) {
    inputDataUploadLogRepository.deleteAllByInputDataUpload(inputDataUpload);
  }
}
