package com.ejie.ab39a.service;
import com.ejie.ab39a.dao.EjeDao;
import com.ejie.x38.dto.JQGridRequestDto;
import com.ejie.x38.dto.JQGridResponseDto;
import com.ejie.x38.dto.TableRowDto;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.ejie.ab39a.model.Eje;

/**
 * Eje.
 *  
 */
@Service(value = "ejeService")
public class EjeServiceImpl implements EjeService {

	@Autowired
	private EjeDao ejeDao;

	/**
	 * Inserts a single row in the Eje table.
	 *
	 * @param eje Eje
	 * @return Eje
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class)
	public Eje add(Eje eje) {
		return this.ejeDao.add(eje);
	}

	/**
	 * Updates a single row in the Eje table.
	 *
	 * @param eje Eje
	 * @return Eje
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class)
	public Eje update(Eje eje) {
		return this.ejeDao.update(eje);
	 }

	/**
	 * Finds a single row in the Eje table.
	 *
	 * @param eje Eje
	 * @return Eje
	 */
	@Override
	@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED)
	public Eje find(Eje eje) {
		return this.ejeDao.find(eje);
	}
	
	/**
	 * Deletes a single row in the Eje table.
	 *
	 * @param eje Eje
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class)
	public void remove(Eje eje) {
		this.ejeDao.remove(eje);
	}

	/**
	 * Finds a list of rows in the Eje table.
	 *
	 * @param eje Eje
	 * @param jqGridRequestDto JQGridRequestDto
	 * @return List<Eje>
	 */
	@Override
	@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED)
	public List<Eje> findAll(Eje eje, JQGridRequestDto jqGridRequestDto){
		return this.ejeDao.findAll(eje, jqGridRequestDto);
	}
    
	/**
	 * Finds rows in the Eje table using like.
	 *
	 * @param eje Eje
	 * @param jqGridRequestDto JQGridRequestDto
     * @param startsWith Boolean	 
	 * @return List<Eje>
	 */
	@Override
	@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED) 
	public List<Eje> findAllLike(Eje eje, JQGridRequestDto jqGridRequestDto, Boolean startsWith){
		return this.ejeDao.findAllLike(eje, jqGridRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE
	 */
	 
	/**
	 * Removes rows from the Eje table.
	 *
	 * @param filterEje Eje
	 * @param jqGridRequestDto JQGridRequestDto
	 * @param startsWith Boolean
	 */	
	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class)
	public void removeMultiple(Eje filterEje, JQGridRequestDto jqGridRequestDto,  Boolean startsWith){
		this.ejeDao.removeMultiple(filterEje, jqGridRequestDto, startsWith);
	}
        
	/**
	 * Filter method in the Eje table.
	 *
	 * @param filterEje Eje
	 * @param jqGridRequestDto JQGridRequestDto
	 * @param startsWith Boolean
	 * @return JQGridResponseDto<Eje>
	 */
	@Override	
	@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED)
	public JQGridResponseDto< Eje> filter(Eje filterEje, JQGridRequestDto jqGridRequestDto,  Boolean startsWith){
		List<Eje> listaEje =  this.ejeDao.findAllLike(filterEje, jqGridRequestDto, false);
		Long recordNum =  this.ejeDao.findAllLikeCount(filterEje != null ? filterEje: new Eje (),false);
		if (jqGridRequestDto.getMultiselection().getSelectedIds()!=null){
			List< TableRowDto< Eje>> reorderSelection = this.ejeDao.reorderSelection(filterEje, jqGridRequestDto, startsWith);
			return new JQGridResponseDto<Eje>(jqGridRequestDto, recordNum, listaEje, reorderSelection);
		}
		return new JQGridResponseDto<Eje>(jqGridRequestDto, recordNum, listaEje);   
	}
    
    /**
	 * Reorder the selection made in Eje table.
	 *
	 * @param filterEje Eje
	 * @param jqGridRequestDto JQGridRequestDto
	 * @param startsWith Boolean
	 * @return Object
	 */	
	@Override
    @Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED)
    public Object reorderSelection(Eje filterEje, JQGridRequestDto jqGridRequestDto, Boolean startsWith){
		return this.ejeDao.reorderSelection(filterEje, jqGridRequestDto, startsWith);
	}
    	
}
