package vn.azteam.tpf.service.impl;

import vn.azteam.tpf.service.TBGuidelineDetailsObjectUpdateService;
import vn.azteam.tpf.domain.TBGuidelineDetailsObjectUpdate;
import vn.azteam.tpf.repository.TBGuidelineDetailsObjectUpdateRepository;
import vn.azteam.tpf.repository.search.TBGuidelineDetailsObjectUpdateSearchRepository;
import vn.azteam.tpf.service.dto.TBGuidelineDetailsObjectUpdateDTO;
import vn.azteam.tpf.service.mapper.TBGuidelineDetailsObjectUpdateMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

import static org.elasticsearch.index.query.QueryBuilders.*;

/**
 * Service Implementation for managing TBGuidelineDetailsObjectUpdate.
 */
@Service
@Transactional
public class TBGuidelineDetailsObjectUpdateServiceImpl implements TBGuidelineDetailsObjectUpdateService {

    private final Logger log = LoggerFactory.getLogger(TBGuidelineDetailsObjectUpdateServiceImpl.class);

    private final TBGuidelineDetailsObjectUpdateRepository tBGuidelineDetailsObjectUpdateRepository;

    private final TBGuidelineDetailsObjectUpdateMapper tBGuidelineDetailsObjectUpdateMapper;

    private final TBGuidelineDetailsObjectUpdateSearchRepository tBGuidelineDetailsObjectUpdateSearchRepository;

    public TBGuidelineDetailsObjectUpdateServiceImpl(TBGuidelineDetailsObjectUpdateRepository tBGuidelineDetailsObjectUpdateRepository, TBGuidelineDetailsObjectUpdateMapper tBGuidelineDetailsObjectUpdateMapper, TBGuidelineDetailsObjectUpdateSearchRepository tBGuidelineDetailsObjectUpdateSearchRepository) {
        this.tBGuidelineDetailsObjectUpdateRepository = tBGuidelineDetailsObjectUpdateRepository;
        this.tBGuidelineDetailsObjectUpdateMapper = tBGuidelineDetailsObjectUpdateMapper;
        this.tBGuidelineDetailsObjectUpdateSearchRepository = tBGuidelineDetailsObjectUpdateSearchRepository;
    }

    /**
     * Save a tBGuidelineDetailsObjectUpdate.
     *
     * @param tBGuidelineDetailsObjectUpdateDTO the entity to save
     * @return the persisted entity
     */
    @Override
    public TBGuidelineDetailsObjectUpdateDTO save(TBGuidelineDetailsObjectUpdateDTO tBGuidelineDetailsObjectUpdateDTO) {
        log.debug("Request to save TBGuidelineDetailsObjectUpdate : {}", tBGuidelineDetailsObjectUpdateDTO);

        TBGuidelineDetailsObjectUpdate tBGuidelineDetailsObjectUpdate = tBGuidelineDetailsObjectUpdateMapper.toEntity(tBGuidelineDetailsObjectUpdateDTO);
        tBGuidelineDetailsObjectUpdate = tBGuidelineDetailsObjectUpdateRepository.save(tBGuidelineDetailsObjectUpdate);
        TBGuidelineDetailsObjectUpdateDTO result = tBGuidelineDetailsObjectUpdateMapper.toDto(tBGuidelineDetailsObjectUpdate);
        tBGuidelineDetailsObjectUpdateSearchRepository.save(tBGuidelineDetailsObjectUpdate);
        return result;
    }

    /**
     * Get all the tBGuidelineDetailsObjectUpdates.
     *
     * @param pageable the pagination information
     * @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public Page<TBGuidelineDetailsObjectUpdateDTO> findAll(Pageable pageable) {
        log.debug("Request to get all TBGuidelineDetailsObjectUpdates");
        return tBGuidelineDetailsObjectUpdateRepository.findAll(pageable)
            .map(tBGuidelineDetailsObjectUpdateMapper::toDto);
    }


    /**
     * Get one tBGuidelineDetailsObjectUpdate by id.
     *
     * @param id the id of the entity
     * @return the entity
     */
    @Override
    @Transactional(readOnly = true)
    public Optional<TBGuidelineDetailsObjectUpdateDTO> findOne(Long id) {
        log.debug("Request to get TBGuidelineDetailsObjectUpdate : {}", id);
        return tBGuidelineDetailsObjectUpdateRepository.findById(id)
            .map(tBGuidelineDetailsObjectUpdateMapper::toDto);
    }

    /**
     * Delete the tBGuidelineDetailsObjectUpdate by id.
     *
     * @param id the id of the entity
     */
    @Override
    public void delete(Long id) {
        log.debug("Request to delete TBGuidelineDetailsObjectUpdate : {}", id);
        tBGuidelineDetailsObjectUpdateRepository.deleteById(id);
        tBGuidelineDetailsObjectUpdateSearchRepository.deleteById(id);
    }

    /**
     * Search for the tBGuidelineDetailsObjectUpdate corresponding to the query.
     *
     * @param query the query of the search
     * @param pageable the pagination information
     * @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public Page<TBGuidelineDetailsObjectUpdateDTO> search(String query, Pageable pageable) {
        log.debug("Request to search for a page of TBGuidelineDetailsObjectUpdates for query {}", query);
        return tBGuidelineDetailsObjectUpdateSearchRepository.search(queryStringQuery(query), pageable)
            .map(tBGuidelineDetailsObjectUpdateMapper::toDto);
    }
}
