package vn.azteam.tpf.service.impl;

import vn.azteam.tpf.service.TBEntityLocationOfCustomerService;
import vn.azteam.tpf.domain.TBEntityLocationOfCustomer;
import vn.azteam.tpf.repository.TBEntityLocationOfCustomerRepository;
import vn.azteam.tpf.repository.search.TBEntityLocationOfCustomerSearchRepository;
import vn.azteam.tpf.service.dto.TBEntityLocationOfCustomerDTO;
import vn.azteam.tpf.service.mapper.TBEntityLocationOfCustomerMapper;
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 TBEntityLocationOfCustomer.
 */
@Service
@Transactional
public class TBEntityLocationOfCustomerServiceImpl implements TBEntityLocationOfCustomerService {

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

    private final TBEntityLocationOfCustomerRepository tBEntityLocationOfCustomerRepository;

    private final TBEntityLocationOfCustomerMapper tBEntityLocationOfCustomerMapper;

    private final TBEntityLocationOfCustomerSearchRepository tBEntityLocationOfCustomerSearchRepository;

    public TBEntityLocationOfCustomerServiceImpl(TBEntityLocationOfCustomerRepository tBEntityLocationOfCustomerRepository, TBEntityLocationOfCustomerMapper tBEntityLocationOfCustomerMapper, TBEntityLocationOfCustomerSearchRepository tBEntityLocationOfCustomerSearchRepository) {
        this.tBEntityLocationOfCustomerRepository = tBEntityLocationOfCustomerRepository;
        this.tBEntityLocationOfCustomerMapper = tBEntityLocationOfCustomerMapper;
        this.tBEntityLocationOfCustomerSearchRepository = tBEntityLocationOfCustomerSearchRepository;
    }

    /**
     * Save a tBEntityLocationOfCustomer.
     *
     * @param tBEntityLocationOfCustomerDTO the entity to save
     * @return the persisted entity
     */
    @Override
    public TBEntityLocationOfCustomerDTO save(TBEntityLocationOfCustomerDTO tBEntityLocationOfCustomerDTO) {
        log.debug("Request to save TBEntityLocationOfCustomer : {}", tBEntityLocationOfCustomerDTO);

        TBEntityLocationOfCustomer tBEntityLocationOfCustomer = tBEntityLocationOfCustomerMapper.toEntity(tBEntityLocationOfCustomerDTO);
        tBEntityLocationOfCustomer = tBEntityLocationOfCustomerRepository.save(tBEntityLocationOfCustomer);
        TBEntityLocationOfCustomerDTO result = tBEntityLocationOfCustomerMapper.toDto(tBEntityLocationOfCustomer);
        tBEntityLocationOfCustomerSearchRepository.save(tBEntityLocationOfCustomer);
        return result;
    }

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


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

    /**
     * Delete the tBEntityLocationOfCustomer by id.
     *
     * @param id the id of the entity
     */
    @Override
    public void delete(Long id) {
        log.debug("Request to delete TBEntityLocationOfCustomer : {}", id);
        tBEntityLocationOfCustomerRepository.deleteById(id);
        tBEntityLocationOfCustomerSearchRepository.deleteById(id);
    }

    /**
     * Search for the tBEntityLocationOfCustomer 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<TBEntityLocationOfCustomerDTO> search(String query, Pageable pageable) {
        log.debug("Request to search for a page of TBEntityLocationOfCustomers for query {}", query);
        return tBEntityLocationOfCustomerSearchRepository.search(queryStringQuery(query), pageable)
            .map(tBEntityLocationOfCustomerMapper::toDto);
    }
}
