package com.ejie.ab61.service.plantillas;

import com.ejie.x38.dto.JQGridRequestDto;
import com.ejie.x38.dto.JQGridResponseDto;
import com.ejie.x38.dto.JerarquiaDto;
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.ab61.dao.plantillas.RelTipPlaProDao;
import com.ejie.ab61.model.plantillas.RelTipPlaPro;
import com.ejie.ab61.model.plantillas.TiposPlantilla;

/**
 * RelTipPlaProServiceImpl  
 * 
 *  
 */

@Service(value = "relTipPlaProService")
public class RelTipPlaProServiceImpl implements RelTipPlaProService {

	@Autowired
	private RelTipPlaProDao relTipPlaProDao;

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

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

	/**
	 * Finds a single row in the RelTipPlaPro table.
	 *
	 * @param relTipPlaPro
	 *            RelTipPlaPro
	 * @return RelTipPlaPro
	 */
	public RelTipPlaPro find(RelTipPlaPro relTipPlaPro) {
		return (RelTipPlaPro) this.relTipPlaProDao.find(relTipPlaPro);
	}

	/**
	 * Deletes a single row in the RelTipPlaPro table.
	 *
	 * @param relTipPlaPro
	 *            RelTipPlaPro
	 */
	@Transactional(rollbackFor = Throwable.class)
	public void remove(RelTipPlaPro relTipPlaPro) {
		this.relTipPlaProDao.remove(relTipPlaPro);
	}

	/**
	 * Finds a list of rows in the RelTipPlaPro table.
	 *
	 * @param relTipPlaPro
	 *            RelTipPlaPro
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @return List<RelTipPlaPro>
	 */
	public List<RelTipPlaPro> findAll(RelTipPlaPro relTipPlaPro, JQGridRequestDto jqGridRequestDto) {
		return (List<RelTipPlaPro>) this.relTipPlaProDao.findAll(relTipPlaPro, jqGridRequestDto);
	}

	/**
	 * Finds rows in the RelTipPlaPro table using like.
	 *
	 * @param relTipPlaPro
	 *            RelTipPlaPro
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<RelTipPlaPro>
	 */
	public List<RelTipPlaPro> findAllLike(RelTipPlaPro relTipPlaPro, JQGridRequestDto jqGridRequestDto,
			Boolean startsWith) {
		return (List<RelTipPlaPro>) this.relTipPlaProDao.findAllLike(relTipPlaPro, jqGridRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE
	 */

	/**
	 * Removes rows from the RelTipPlaPro table.
	 *
	 * @param filterRelTipPlaPro
	 *            RelTipPlaPro
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 */
	public void removeMultiple(RelTipPlaPro filterRelTipPlaPro, JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		this.relTipPlaProDao.removeMultiple(filterRelTipPlaPro, jqGridRequestDto, startsWith);
	}

	/**
	 * Filter method in the RelTipPlaPro table.
	 *
	 * @param filterRelTipPlaPro
	 *            RelTipPlaPro
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return JQGridResponseDto<RelTipPlaPro>
	 */
	public JQGridResponseDto<RelTipPlaPro> filter(RelTipPlaPro filterRelTipPlaPro, JQGridRequestDto jqGridRequestDto,
			Boolean startsWith) {
		List<RelTipPlaPro> listaRelTipPlaPro = this.relTipPlaProDao.findAllLike(filterRelTipPlaPro, jqGridRequestDto,
				false);
		Long recordNum = this.relTipPlaProDao
				.findAllLikeCount(filterRelTipPlaPro != null ? filterRelTipPlaPro : new RelTipPlaPro(), false);
		if (jqGridRequestDto.getMultiselection().getSelectedIds() != null) {
			List<TableRowDto<RelTipPlaPro>> reorderSelection = this.relTipPlaProDao.reorderSelection(filterRelTipPlaPro,
					jqGridRequestDto, startsWith);
			return new JQGridResponseDto<RelTipPlaPro>(jqGridRequestDto, recordNum, listaRelTipPlaPro,
					reorderSelection);
		}
		return new JQGridResponseDto<RelTipPlaPro>(jqGridRequestDto, recordNum, listaRelTipPlaPro);
	}

	/**
	 * Searches rows in the RelTipPlaPro table.
	 *
	 * @param filterRelTipPlaPro
	 *            RelTipPlaPro
	 * @param searchRelTipPlaPro
	 *            RelTipPlaPro
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<TableRowDto<RelTipPlaPro>>
	 */
	public List<TableRowDto<RelTipPlaPro>> search(RelTipPlaPro filterRelTipPlaPro, RelTipPlaPro searchRelTipPlaPro,
			JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		return this.relTipPlaProDao.search(filterRelTipPlaPro, searchRelTipPlaPro, jqGridRequestDto, startsWith);
	}

	/**
	 * Reorder the selection made in RelTipPlaPro table.
	 *
	 * @param filterRelTipPlaPro
	 *            RelTipPlaPro
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return Object
	 */
	public Object reorderSelection(RelTipPlaPro filterRelTipPlaPro, JQGridRequestDto jqGridRequestDto,
			Boolean startsWith) {
		return this.relTipPlaProDao.reorderSelection(filterRelTipPlaPro, jqGridRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE JERARQUIA
	 */

	/**
	 * Finder method in the hierarchical the RelTipPlaPro table.
	 *
	 * @param filterRelTipPlaPro
	 *            RelTipPlaPro
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return JQGridResponseDto<JerarquiaDto<RelTipPlaPro>>
	 */
	public JQGridResponseDto<JerarquiaDto<RelTipPlaPro>> jerarquia(RelTipPlaPro filterRelTipPlaPro,
			JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		List<JerarquiaDto<RelTipPlaPro>> listaRelTipPlaPro = this.relTipPlaProDao
				.findAllLikeJerarquia(filterRelTipPlaPro, jqGridRequestDto);
		Long recordNum = this.relTipPlaProDao.findAllLikeCountJerarquia(filterRelTipPlaPro, jqGridRequestDto);
		return new JQGridResponseDto<JerarquiaDto<RelTipPlaPro>>(jqGridRequestDto, recordNum, listaRelTipPlaPro);
	}

	/**
	 * Finder method for siblings rows in the hierarchical the RelTipPlaPro
	 * table.
	 *
	 * @param filterRelTipPlaPro
	 *            RelTipPlaPro
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @return JQGridResponseDto<JerarquiaDto<RelTipPlaPro>>
	 */
	public JQGridResponseDto<JerarquiaDto<RelTipPlaPro>> jerarquiaChildren(RelTipPlaPro filterRelTipPlaPro,
			JQGridRequestDto jqGridRequestDto) {
		JQGridResponseDto<JerarquiaDto<RelTipPlaPro>> jqGridResponseDto = new JQGridResponseDto<JerarquiaDto<RelTipPlaPro>>();
		jqGridResponseDto.addAdditionalParam(JQGridResponseDto.CHILDREN,
				this.relTipPlaProDao.findAllChild(filterRelTipPlaPro, jqGridRequestDto));
		return jqGridResponseDto;
	}

	@Override
	public List<RelTipPlaPro> findByTipoPlantilla(TiposPlantilla tiposPlantilla) {
		return this.relTipPlaProDao.findByTipoPlantilla(tiposPlantilla);
	}

	@Override
	public void removeByTipoPlantilla(TiposPlantilla tiposPlantilla) {
		this.relTipPlaProDao.removeByTipoPlantilla(tiposPlantilla);
	}

}
