package com.ejie.ab79.service.actuaciones;
import com.ejie.x38.dto.JerarquiaDto;
import com.ejie.x38.dto.TableRequestDto;
import com.ejie.x38.dto.TableResponseDto;
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;

import com.ejie.ab79.dao.actuaciones.DesResActDao;
import com.ejie.ab79.model.actuaciones.DesResAct;

/**
 * DesResActServiceImpl  
 *  
 */

@Service(value = "desResActService")
public class DesResActServiceImpl implements DesResActService {

	@Autowired
	private DesResActDao desResActDao;

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

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

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

	/**
	 * Finds a list of rows in the DesResAct table.
	 *
	 * @param desResAct DesResAct
	 * @param tableRequestDto TableRequestDto
	 * @return List<DesResAct>
	 */
	public List<DesResAct> findAll(DesResAct desResAct, TableRequestDto tableRequestDto){
		return (List<DesResAct>) this.desResActDao.findAll(desResAct, tableRequestDto);
	}
    
	/**
	 * Finds rows in the DesResAct table using like.
	 *
	 * @param desResAct DesResAct
	 * @param tableRequestDto TableRequestDto
     * @param startsWith Boolean	 
	 * @return List<DesResAct>
	 */
	public List<DesResAct> findAllLike(DesResAct desResAct, TableRequestDto tableRequestDto, Boolean startsWith){
		return (List<DesResAct>) this.desResActDao.findAllLike(desResAct, tableRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE
	 */
	 
	/**
	 * Removes rows from the DesResAct table.
	 *
	 * @param filterDesResAct DesResAct
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith Boolean
	 */	
	public void removeMultiple(DesResAct filterDesResAct, TableRequestDto tableRequestDto,  Boolean startsWith){
		this.desResActDao.removeMultiple(filterDesResAct, tableRequestDto, startsWith);
	}
        
	/**
	 * Filter method in the DesResAct table.
	 *
	 * @param filterDesResAct DesResAct
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith Boolean
	 * @return TableResponseDto<DesResAct>
	 */	
	public TableResponseDto< DesResAct> filter(DesResAct filterDesResAct, TableRequestDto tableRequestDto,  Boolean startsWith){
		List<DesResAct> listaDesResAct =  this.desResActDao.findAllLike(filterDesResAct, tableRequestDto, false);
		Long recordNum =  this.desResActDao.findAllLikeCount(filterDesResAct != null ? filterDesResAct: new DesResAct (),false);
		
		TableResponseDto<DesResAct> usuarioDto = new TableResponseDto<DesResAct>(tableRequestDto, recordNum, listaDesResAct);
		
		if (tableRequestDto.getMultiselection().getSelectedIds()!=null){
			List< TableRowDto< DesResAct>> reorderSelection = this.desResActDao.reorderSelection(filterDesResAct, tableRequestDto, startsWith);
			usuarioDto.setReorderedSelection(reorderSelection);
			usuarioDto.addAdditionalParam("reorderedSelection", reorderSelection);
			usuarioDto.addAdditionalParam("selectedAll", tableRequestDto.getMultiselection().getSelectedAll());
		}
		if (tableRequestDto.getSeeker().getSelectedIds()!=null){
			tableRequestDto.setMultiselection(tableRequestDto.getSeeker());
			List< TableRowDto< DesResAct>> reorderSeeker = this.desResActDao.reorderSelection(filterDesResAct, tableRequestDto, startsWith);
			usuarioDto.setReorderedSeeker(reorderSeeker);
			usuarioDto.addAdditionalParam("reorderedSeeker", reorderSeeker);
		}
		return usuarioDto;   
	}
    /**
	 * Searches rows in the DesResAct table.
	 *
	 * @param filterDesResAct DesResAct
	 * @param searchDesResAct DesResAct
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith Boolean
	 * @return List<TableRowDto<DesResAct>>
	 */	
    public List< TableRowDto< DesResAct>> search(DesResAct filterDesResAct, DesResAct searchDesResAct, TableRequestDto tableRequestDto, Boolean startsWith){
		return this.desResActDao.search(filterDesResAct, searchDesResAct, tableRequestDto, startsWith);
	}
    
    /**
	 * Reorder the selection made in DesResAct table.
	 *
	 * @param filterDesResAct DesResAct
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith Boolean
	 * @return Object
	 */	
    public Object reorderSelection(DesResAct filterDesResAct, TableRequestDto tableRequestDto, Boolean startsWith){
		return this.desResActDao.reorderSelection(filterDesResAct, tableRequestDto, startsWith);
	}
    
    /*
	 * OPERACIONES RUP_TABLE JERARQUIA
	 */
	 
	/**
	 * Finder method in the hierarchical the DesResAct table.
	 *
	 * @param filterDesResAct DesResAct
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith Boolean
	 * @return TableResponseDto<JerarquiaDto<DesResAct>>
	 */	
	public TableResponseDto<JerarquiaDto<DesResAct>> jerarquia(DesResAct filterDesResAct, TableRequestDto tableRequestDto, Boolean startsWith){
		List<JerarquiaDto<DesResAct>> listaDesResAct =  this.desResActDao.findAllLikeJerarquia(filterDesResAct, tableRequestDto);
		Long recordNum = this.desResActDao.findAllLikeCountJerarquia(filterDesResAct, tableRequestDto);
		return new TableResponseDto<JerarquiaDto<DesResAct>>(tableRequestDto, recordNum, listaDesResAct);
	}
	
	/**
	 * Finder method for siblings rows in the hierarchical the DesResAct table.
	 *
	 * @param filterDesResAct DesResAct
	 * @param tableRequestDto TableRequestDto
	 * @return TableResponseDto<JerarquiaDto<DesResAct>>
	 */	
	public TableResponseDto<JerarquiaDto<DesResAct>> jerarquiaChildren(DesResAct filterDesResAct, TableRequestDto tableRequestDto){
		TableResponseDto<JerarquiaDto<DesResAct>> tableResponseDto = new TableResponseDto<JerarquiaDto<DesResAct>>();
		tableResponseDto.addAdditionalParam(TableResponseDto.CHILDREN, this.desResActDao.findAllChild(filterDesResAct, tableRequestDto));
		return tableResponseDto;
	}
	
	/**
    * Exporta Datos al clipBoard
    *
    */
    public List<DesResAct> getMultiple(DesResAct filterDesResAct, TableRequestDto tableRequestDto,  Boolean startsWith){
		return this.desResActDao.getMultiple(filterDesResAct, tableRequestDto, startsWith);
	}
      
	
	
}

