package com.ejie.ab61.service.documentosPid;

import com.ejie.ab61.dao.documentosPid.DocumentosPidDao;
import com.ejie.ab61.model.documentosPid.DocumentosPid;
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;

/**
 * DocumentosPidServiceImpl  
 * 
 *  
 */

@Service(value = "documentosPidService")
public class DocumentosPidServiceImpl implements DocumentosPidService {

	@Autowired
	private DocumentosPidDao documentosPidDao;

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

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

	/**
	 * Finds a single row in the DocumentosPid table.
	 *
	 * @param documentosPid
	 *            DocumentosPid
	 * @return DocumentosPid
	 */
	public DocumentosPid find(DocumentosPid documentosPid) {
		return (DocumentosPid) this.documentosPidDao.find(documentosPid);
	}

	@Override
	public DocumentosPid findIdByOidPid(String oidPid) {
		return (DocumentosPid) this.documentosPidDao.findIdByOidPid(oidPid);
	}

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

	@Override
	public void removeByOidPid(String oidPid) {
		this.documentosPidDao.removeByOidPid(oidPid);
	}

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

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

	/*
	 * OPERACIONES RUP_TABLE
	 */

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

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

	/**
	 * Searches rows in the DocumentosPid table.
	 *
	 * @param filterDocumentosPid
	 *            DocumentosPid
	 * @param searchDocumentosPid
	 *            DocumentosPid
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<TableRowDto<DocumentosPid>>
	 */
	public List<TableRowDto<DocumentosPid>> search(DocumentosPid filterDocumentosPid, DocumentosPid searchDocumentosPid,
			JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		return this.documentosPidDao.search(filterDocumentosPid, searchDocumentosPid, jqGridRequestDto, startsWith);
	}

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

	/*
	 * OPERACIONES RUP_TABLE JERARQUIA
	 */

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

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

}
