package com.ejie.ab79.service;
import com.ejie.ab79.dao.DocumentosJsonDao;
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.model.DocumentosJson;

/**
 * DocumentosJsonServiceImpl  
 *  
 */

@Service(value = "documentosJsonService")
public class DocumentosJsonServiceImpl implements DocumentosJsonService {

	@Autowired
	private DocumentosJsonDao documentosJsonDao;

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

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

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

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

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

