package com.ejie.ab61.service.solicitudes;
import com.ejie.ab61.dao.solicitudes.SolicitudesDao;
import com.ejie.ab61.model.solicitudes.Solicitudes;
import com.ejie.x38.dto.JQGridRequestDto;
import com.ejie.x38.dto.JQGridResponseDto;
import com.ejie.x38.dto.JerarquiaDto;
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.Transactional;

/**
 * SolicitudesServiceImpl  
 *  
 */

@Service(value = "solicitudesService")
public class SolicitudesServiceImpl implements SolicitudesService {

	@Autowired
	private SolicitudesDao solicitudesDao;

	/**
	 * Inserts a single row in the Solicitudes table.
	 *
	 * @param solicitudes Solicitudes
	 * @return Solicitudes
	 */
	@Transactional(rollbackFor = Throwable.class)
	public Solicitudes add(Solicitudes solicitudes) {
		return this.solicitudesDao.add(solicitudes);
	}

	/**
	 * Updates a single row in the Solicitudes table.
	 *
	 * @param solicitudes Solicitudes
	 * @return Solicitudes
	 */
	@Transactional(rollbackFor = Throwable.class)
	public Solicitudes update(Solicitudes solicitudes) {
		return this.solicitudesDao.update(solicitudes);
	 }

	/**
	 * Finds a single row in the Solicitudes table.
	 *
	 * @param solicitudes Solicitudes
	 * @return Solicitudes
	 */
	public Solicitudes find(Solicitudes solicitudes) {
		return (Solicitudes) this.solicitudesDao.find(solicitudes);
	}
	
	/**
	 * Deletes a single row in the Solicitudes table.
	 *
	 * @param solicitudes Solicitudes
	 */
	@Transactional(rollbackFor = Throwable.class)
	public void remove(Solicitudes solicitudes) {
		this.solicitudesDao.remove(solicitudes);
	}

	/**
	 * Finds a list of rows in the Solicitudes table.
	 *
	 * @param solicitudes Solicitudes
	 * @param jqGridRequestDto JQGridRequestDto
	 * @return List<Solicitudes>
	 */
	public List<Solicitudes> findAll(Solicitudes solicitudes, JQGridRequestDto jqGridRequestDto){
		return (List<Solicitudes>) this.solicitudesDao.findAll(solicitudes, jqGridRequestDto);
	}
    
	/**
	 * Finds rows in the Solicitudes table using like.
	 *
	 * @param solicitudes Solicitudes
	 * @param jqGridRequestDto JQGridRequestDto
     * @param startsWith Boolean	 
	 * @return List<Solicitudes>
	 */
	public List<Solicitudes> findAllLike(Solicitudes solicitudes, JQGridRequestDto jqGridRequestDto, Boolean startsWith){
		return (List<Solicitudes>) this.solicitudesDao.findAllLike(solicitudes, jqGridRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE
	 */
	 
	/**
	 * Removes rows from the Solicitudes table.
	 *
	 * @param filterSolicitudes Solicitudes
	 * @param jqGridRequestDto JQGridRequestDto
	 * @param startsWith Boolean
	 */	
	public void removeMultiple(Solicitudes filterSolicitudes, JQGridRequestDto jqGridRequestDto,  Boolean startsWith){
		this.solicitudesDao.removeMultiple(filterSolicitudes, jqGridRequestDto, startsWith);
	}
        
	/**
	 * Filter method in the Solicitudes table.
	 *
	 * @param filterSolicitudes Solicitudes
	 * @param jqGridRequestDto JQGridRequestDto
	 * @param startsWith Boolean
	 * @return JQGridResponseDto<Solicitudes>
	 */	
	public JQGridResponseDto< Solicitudes> filter(Solicitudes filterSolicitudes, JQGridRequestDto jqGridRequestDto,  Boolean startsWith){
		List<Solicitudes> listaSolicitudes =  this.solicitudesDao.findAllLike(filterSolicitudes, jqGridRequestDto, false);
		Long recordNum =  this.solicitudesDao.findAllLikeCount(filterSolicitudes != null ? filterSolicitudes: new Solicitudes (),false);
		if (jqGridRequestDto.getMultiselection().getSelectedIds()!=null){
			List< TableRowDto< Solicitudes>> reorderSelection = this.solicitudesDao.reorderSelection(filterSolicitudes, jqGridRequestDto, startsWith);
			return new JQGridResponseDto<Solicitudes>(jqGridRequestDto, recordNum, listaSolicitudes, reorderSelection);
		}
		return new JQGridResponseDto<Solicitudes>(jqGridRequestDto, recordNum, listaSolicitudes);   
	}
    
    /**
	 * Searches rows in the Solicitudes table.
	 *
	 * @param filterSolicitudes Solicitudes
	 * @param searchSolicitudes Solicitudes
	 * @param jqGridRequestDto JQGridRequestDto
	 * @param startsWith Boolean
	 * @return List<TableRowDto<Solicitudes>>
	 */	
    public List< TableRowDto< Solicitudes>> search(Solicitudes filterSolicitudes, Solicitudes searchSolicitudes, JQGridRequestDto jqGridRequestDto, Boolean startsWith){
		return this.solicitudesDao.search(filterSolicitudes, searchSolicitudes, jqGridRequestDto, startsWith);
	}
    
    /**
	 * Reorder the selection made in Solicitudes table.
	 *
	 * @param filterSolicitudes Solicitudes
	 * @param jqGridRequestDto JQGridRequestDto
	 * @param startsWith Boolean
	 * @return Object
	 */	
    public Object reorderSelection(Solicitudes filterSolicitudes, JQGridRequestDto jqGridRequestDto, Boolean startsWith){
		return this.solicitudesDao.reorderSelection(filterSolicitudes, jqGridRequestDto, startsWith);
	}
    
    /*
	 * OPERACIONES RUP_TABLE JERARQUIA
	 */
	 
	/**
	 * Finder method in the hierarchical the Solicitudes table.
	 *
	 * @param filterSolicitudes Solicitudes
	 * @param jqGridRequestDto JQGridRequestDto
	 * @param startsWith Boolean
	 * @return JQGridResponseDto<JerarquiaDto<Solicitudes>>
	 */	
	public JQGridResponseDto<JerarquiaDto<Solicitudes>> jerarquia(Solicitudes filterSolicitudes, JQGridRequestDto jqGridRequestDto, Boolean startsWith){
		List<JerarquiaDto<Solicitudes>> listaSolicitudes =  this.solicitudesDao.findAllLikeJerarquia(filterSolicitudes, jqGridRequestDto);
		Long recordNum = this.solicitudesDao.findAllLikeCountJerarquia(filterSolicitudes, jqGridRequestDto);
		return new JQGridResponseDto<JerarquiaDto<Solicitudes>>(jqGridRequestDto, recordNum, listaSolicitudes);
	}
	
	/**
	 * Finder method for siblings rows in the hierarchical the Solicitudes table.
	 *
	 * @param filterSolicitudes Solicitudes
	 * @param jqGridRequestDto JQGridRequestDto
	 * @return JQGridResponseDto<JerarquiaDto<Solicitudes>>
	 */	
	public JQGridResponseDto<JerarquiaDto<Solicitudes>> jerarquiaChildren(Solicitudes filterSolicitudes, JQGridRequestDto jqGridRequestDto){
		JQGridResponseDto<JerarquiaDto<Solicitudes>> jqGridResponseDto = new JQGridResponseDto<JerarquiaDto<Solicitudes>>();
		jqGridResponseDto.addAdditionalParam(JQGridResponseDto.CHILDREN, this.solicitudesDao.findAllChild(filterSolicitudes, jqGridRequestDto));
		return jqGridResponseDto;
	}
	
	
}

