/*
* Copyright 2021 E.J.I.E., S.A.
*
* Licencia con arreglo a la EUPL, Versión 1.1 exclusivamente (la «Licencia»);
* Solo podrá usarse esta obra si se respeta la Licencia.
* Puede obtenerse una copia de la Licencia en
*
* http://ec.europa.eu/idabc/eupl.html
*
* Salvo cuando lo exija la legislación aplicable o se acuerde por escrito,
* el programa distribuido con arreglo a la Licencia se distribuye «TAL CUAL»,
* SIN GARANT�?AS NI CONDICIONES DE NINGÚN TIPO, ni expresas ni implícitas.
* Véase la Licencia en el idioma concreto que rige los permisos y limitaciones
* que establece la Licencia.
*/
package com.ejie.ad74a.service.ae01b;

import com.ejie.ad74a.dao.ae01b.CobrosDao;
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 com.ejie.ad74a.model.ae01b.Cobros;

/**
 * CobrosServiceImpl generated by UDA, 28-jun-2023 10:59:26.
 * 
 * @author UDA
 */

@Service(value = "cobrosService")
public class CobrosServiceImpl implements CobrosService {

	@Autowired
	private CobrosDao cobrosDao;

	/**
	 * Finds a list of rows in the Cobros table.
	 *
	 * @param cobros          Cobros
	 * @param tableRequestDto TableRequestDto
	 *
	 * @return List<Cobros>
	 */
	public List<Cobros> findAll(Cobros cobros, TableRequestDto tableRequestDto) {
		return (List<Cobros>) this.cobrosDao.findAll(cobros, tableRequestDto);
	}

	/**
	 * Finds rows in the Cobros table using like.
	 *
	 * @param cobros          Cobros
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * 
	 * @return List<Cobros>
	 */
	public List<Cobros> findAllLike(Cobros cobros, TableRequestDto tableRequestDto, Boolean startsWith) {
		return (List<Cobros>) this.cobrosDao.findAllLike(cobros, tableRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE
	 */

	/**
	 * Filter method in the Cobros table.
	 *
	 * @param filterCobros    Cobros
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 *
	 * @return TableResponseDto<Cobros>
	 */
	public TableResponseDto<Cobros> filter(Cobros filterCobros, TableRequestDto tableRequestDto, Boolean startsWith) {
		List<Cobros> listaCobros = this.cobrosDao.findAllLike(filterCobros, tableRequestDto, false);
		Long recordNum = this.cobrosDao.findAllLikeCount(filterCobros != null ? filterCobros : new Cobros(), false);
		TableResponseDto<Cobros> tableResponseDto = new TableResponseDto<Cobros>(tableRequestDto, recordNum,
				listaCobros);

		if (tableRequestDto.getMultiselection().getSelectedIds() != null
				&& !tableRequestDto.getMultiselection().getSelectedIds().isEmpty()) {
			List<TableRowDto<Cobros>> reorderSelection = this.cobrosDao.reorderSelection(filterCobros, tableRequestDto,
					startsWith);
			tableResponseDto.setReorderedSelection(reorderSelection);
			tableResponseDto.addAdditionalParam("reorderedSelection", reorderSelection);
			tableResponseDto.addAdditionalParam("selectedAll", tableRequestDto.getMultiselection().getSelectedAll());
		}
		if (tableRequestDto.getSeeker().getSelectedIds() != null) {
			tableRequestDto.setMultiselection(tableRequestDto.getSeeker());
			List<TableRowDto<Cobros>> reorderSeeker = this.cobrosDao.reorderSelection(filterCobros, tableRequestDto,
					startsWith);
			tableResponseDto.setReorderedSeeker(reorderSeeker);
			tableResponseDto.addAdditionalParam("reorderedSeeker", reorderSeeker);
		}
		return tableResponseDto;
	}

	/**
	 * Reorder the selection made in Cobros table.
	 *
	 * @param filterCobros    Cobros
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 *
	 * @return Object
	 */
	public Object reorderSelection(Cobros filterCobros, TableRequestDto tableRequestDto, Boolean startsWith) {
		return this.cobrosDao.reorderSelection(filterCobros, tableRequestDto, startsWith);
	}
}
