package com.ejie.ab79.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ejie.ab79.dao.VReateDocumentosDao;
import com.ejie.ab79.model.VReateDocumentos;
import com.ejie.x38.dto.TableRequestDto;
import com.ejie.x38.dto.TableResponseDto;
import com.ejie.x38.dto.TableRowDto;

/**
 * VReateDocumentosServiceImpl  
 * 
 *  
 */

@Service(value = "vReateDocumentosService")
public class VReateDocumentosServiceImpl implements VReateDocumentosService {

	@Autowired
	private VReateDocumentosDao vReateDocumentosDao;

	@Override
	public TableResponseDto<VReateDocumentos> filterDocumentacionActividad(VReateDocumentos filterVReateDocumentos,
			TableRequestDto tableRequestDto, boolean startsWith) {

		List<VReateDocumentos> listaDocumentosActividad = this.vReateDocumentosDao
				.findDocumentacionActividad(filterVReateDocumentos, tableRequestDto);

		Long recordNum = this.vReateDocumentosDao.findDocumentacionActividadCount(
				filterVReateDocumentos != null ? filterVReateDocumentos : new VReateDocumentos());

		TableResponseDto<VReateDocumentos> usuarioDto = new TableResponseDto<VReateDocumentos>(tableRequestDto,
				recordNum, listaDocumentosActividad);

		if (tableRequestDto.getMultiselection().getSelectedIds() != null) {
			List<TableRowDto<VReateDocumentos>> reorderSelection = this.vReateDocumentosDao
					.reorderSelection(filterVReateDocumentos, 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<VReateDocumentos>> reorderSeeker = this.vReateDocumentosDao
					.reorderSelection(filterVReateDocumentos, tableRequestDto, startsWith);
			usuarioDto.setReorderedSeeker(reorderSeeker);
			usuarioDto.addAdditionalParam("reorderedSeeker", reorderSeeker);
		}
		return usuarioDto;
	}

}
