package com.ejie.ab61.service;

import com.ejie.ab61.dao.VTInsSinExpedienteDao;
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.model.VTInsSinExpediente;

/**
 * VTInsSinExpedienteServiceImpl  
 * 
 *  
 */

@Service(value = "vTInsSinExpedienteService")
public class VTInsSinExpedienteServiceImpl implements VTInsSinExpedienteService {

	@Autowired
	private VTInsSinExpedienteDao vTInsSinExpedienteDao;

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

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

	/**
	 * Finds a single row in the VTInsSinExpediente table.
	 *
	 * @param vTInsSinExpediente
	 *            VTInsSinExpediente
	 * @return VTInsSinExpediente
	 */
	public VTInsSinExpediente find(VTInsSinExpediente vTInsSinExpediente) {
		return (VTInsSinExpediente) this.vTInsSinExpedienteDao.find(vTInsSinExpediente);
	}

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

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

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

	/*
	 * OPERACIONES RUP_TABLE
	 */

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

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

	/**
	 * Searches rows in the VTInsSinExpediente table.
	 *
	 * @param filterVTInsSinExpediente
	 *            VTInsSinExpediente
	 * @param searchVTInsSinExpediente
	 *            VTInsSinExpediente
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<TableRowDto<VTInsSinExpediente>>
	 */
	public List<TableRowDto<VTInsSinExpediente>> search(VTInsSinExpediente filterVTInsSinExpediente,
			VTInsSinExpediente searchVTInsSinExpediente, JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		return this.vTInsSinExpedienteDao.search(filterVTInsSinExpediente, searchVTInsSinExpediente, jqGridRequestDto,
				startsWith);
	}

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

	/*
	 * OPERACIONES RUP_TABLE JERARQUIA
	 */

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

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

	@Override
	public JQGridResponseDto<VTInsSinExpediente> filterInspeccionesARelacionar(
			VTInsSinExpediente filterVTInsSinExpediente, Integer idExpediente, JQGridRequestDto jqGridRequestDto,
			String documentosTitular, boolean startsWith) {
		List<VTInsSinExpediente> listaInspeccionesARelacionar = this.vTInsSinExpedienteDao.findInspeccionesARelacionar(
				filterVTInsSinExpediente, idExpediente, jqGridRequestDto, documentosTitular, startsWith);

		Long recordNum = this.vTInsSinExpedienteDao.findInspeccionesARelacionarCount(filterVTInsSinExpediente,
				documentosTitular, idExpediente, startsWith);

		return new JQGridResponseDto<VTInsSinExpediente>(jqGridRequestDto, recordNum, listaInspeccionesARelacionar);
	}

}
