package com.ejie.ab79.service;
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.EnviosJsonDao;
import com.ejie.ab79.model.EnviosJson;

/**
 * EnviosJsonServiceImpl  
 *  
 */

@Service(value = "enviosJsonService")
public class EnviosJsonServiceImpl implements EnviosJsonService {

	@Autowired
	private EnviosJsonDao enviosJsonDao;

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

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

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

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

	/*
	 * OPERACIONES RUP_TABLE
	 */
	 
	/**
	 * Removes rows from the EnviosJson table.
	 *
	 * @param filterEnviosJson EnviosJson
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith Boolean
	 */	
	public void removeMultiple(EnviosJson filterEnviosJson, TableRequestDto tableRequestDto,  Boolean startsWith){
		this.enviosJsonDao.removeMultiple(filterEnviosJson, tableRequestDto, startsWith);
	}
        
	/**
	 * Filter method in the EnviosJson table.
	 *
	 * @param filterEnviosJson EnviosJson
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith Boolean
	 * @return TableResponseDto<EnviosJson>
	 */	
	public TableResponseDto< EnviosJson> filter(EnviosJson filterEnviosJson, TableRequestDto tableRequestDto,  Boolean startsWith){
		List<EnviosJson> listaEnviosJson =  this.enviosJsonDao.findAllLike(filterEnviosJson, tableRequestDto, false);
		Long recordNum =  this.enviosJsonDao.findAllLikeCount(filterEnviosJson != null ? filterEnviosJson: new EnviosJson (),false);
		
		TableResponseDto<EnviosJson> usuarioDto = new TableResponseDto<EnviosJson>(tableRequestDto, recordNum, listaEnviosJson);
		
		if (tableRequestDto.getMultiselection().getSelectedIds()!=null){
			List< TableRowDto< EnviosJson>> reorderSelection = this.enviosJsonDao.reorderSelection(filterEnviosJson, 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< EnviosJson>> reorderSeeker = this.enviosJsonDao.reorderSelection(filterEnviosJson, tableRequestDto, startsWith);
			usuarioDto.setReorderedSeeker(reorderSeeker);
			usuarioDto.addAdditionalParam("reorderedSeeker", reorderSeeker);
		}
		return usuarioDto;   
	}
    /**
	 * Searches rows in the EnviosJson table.
	 *
	 * @param filterEnviosJson EnviosJson
	 * @param searchEnviosJson EnviosJson
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith Boolean
	 * @return List<TableRowDto<EnviosJson>>
	 */	
    public List< TableRowDto< EnviosJson>> search(EnviosJson filterEnviosJson, EnviosJson searchEnviosJson, TableRequestDto tableRequestDto, Boolean startsWith){
		return this.enviosJsonDao.search(filterEnviosJson, searchEnviosJson, tableRequestDto, startsWith);
	}
    
    /**
	 * Reorder the selection made in EnviosJson table.
	 *
	 * @param filterEnviosJson EnviosJson
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith Boolean
	 * @return Object
	 */	
    public Object reorderSelection(EnviosJson filterEnviosJson, TableRequestDto tableRequestDto, Boolean startsWith){
		return this.enviosJsonDao.reorderSelection(filterEnviosJson, tableRequestDto, startsWith);
	}
    
    /*
	 * OPERACIONES RUP_TABLE JERARQUIA
	 */
	 
	/**
	 * Finder method in the hierarchical the EnviosJson table.
	 *
	 * @param filterEnviosJson EnviosJson
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith Boolean
	 * @return TableResponseDto<JerarquiaDto<EnviosJson>>
	 */	
	public TableResponseDto<JerarquiaDto<EnviosJson>> jerarquia(EnviosJson filterEnviosJson, TableRequestDto tableRequestDto, Boolean startsWith){
		List<JerarquiaDto<EnviosJson>> listaEnviosJson =  this.enviosJsonDao.findAllLikeJerarquia(filterEnviosJson, tableRequestDto);
		Long recordNum = this.enviosJsonDao.findAllLikeCountJerarquia(filterEnviosJson, tableRequestDto);
		return new TableResponseDto<JerarquiaDto<EnviosJson>>(tableRequestDto, recordNum, listaEnviosJson);
	}
	
	/**
	 * Finder method for siblings rows in the hierarchical the EnviosJson table.
	 *
	 * @param filterEnviosJson EnviosJson
	 * @param tableRequestDto TableRequestDto
	 * @return TableResponseDto<JerarquiaDto<EnviosJson>>
	 */	
	public TableResponseDto<JerarquiaDto<EnviosJson>> jerarquiaChildren(EnviosJson filterEnviosJson, TableRequestDto tableRequestDto){
		TableResponseDto<JerarquiaDto<EnviosJson>> tableResponseDto = new TableResponseDto<JerarquiaDto<EnviosJson>>();
		tableResponseDto.addAdditionalParam(TableResponseDto.CHILDREN, this.enviosJsonDao.findAllChild(filterEnviosJson, tableRequestDto));
		return tableResponseDto;
	}
	
	/**
    * Exporta Datos al clipBoard
    *
    */
    public List<EnviosJson> getMultiple(EnviosJson filterEnviosJson, TableRequestDto tableRequestDto,  Boolean startsWith){
		return this.enviosJsonDao.getMultiple(filterEnviosJson, tableRequestDto, startsWith);
	}
      
	
	
}

