package com.ejie.ab63.service;

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.ab63.dao.ModalidadDao;
import com.ejie.ab63.model.Modalidad;
import com.ejie.x38.dto.JQGridRequestDto;
import com.ejie.x38.dto.JQGridResponseDto;
import com.ejie.x38.dto.JerarquiaDto;
import com.ejie.x38.dto.TableRowDto;

/**
 * Ab6314s00ServiceImpl  
 * 
 *  
 */

@Service(value = "modalidadService")
public class ModalidadServiceImpl implements ModalidadService {

	@Autowired
	private ModalidadDao ab6314s00Dao;

	/**
	 * Inserts a single row in the Ab6314s00 table.
	 *
	 * @param ab6314s00
	 *            Ab6314s00
	 * @return Ab6314s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public Modalidad add(Modalidad ab6314s00) {
		return this.ab6314s00Dao.add(ab6314s00);
	}

	/**
	 * Updates a single row in the Ab6314s00 table.
	 *
	 * @param ab6314s00
	 *            Ab6314s00
	 * @return Ab6314s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public Modalidad update(Modalidad ab6314s00) {
		return this.ab6314s00Dao.update(ab6314s00);
	}

	/**
	 * Finds a single row in the Ab6314s00 table.
	 *
	 * @param ab6314s00
	 *            Ab6314s00
	 * @return Ab6314s00
	 */
	public Modalidad find(Modalidad ab6314s00) {
		return (Modalidad) this.ab6314s00Dao.find(ab6314s00);
	}

	/**
	 * Deletes a single row in the Ab6314s00 table.
	 *
	 * @param ab6314s00
	 *            Ab6314s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public void remove(Modalidad ab6314s00) {
		this.ab6314s00Dao.remove(ab6314s00);
	}

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

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

	/*
	 * OPERACIONES RUP_TABLE
	 */

	/**
	 * Removes rows from the Ab6314s00 table.
	 *
	 * @param filterAb6314s00
	 *            Ab6314s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 */
	public void removeMultiple(Modalidad filterAb6314s00, JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		this.ab6314s00Dao.removeMultiple(filterAb6314s00, jqGridRequestDto, startsWith);
	}

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

	/**
	 * Searches rows in the Ab6314s00 table.
	 *
	 * @param filterAb6314s00
	 *            Ab6314s00
	 * @param searchAb6314s00
	 *            Ab6314s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<TableRowDto<Ab6314s00>>
	 */
	public List<TableRowDto<Modalidad>> search(Modalidad filterAb6314s00, Modalidad searchAb6314s00,
			JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		return this.ab6314s00Dao.search(filterAb6314s00, searchAb6314s00, jqGridRequestDto, startsWith);
	}

	/**
	 * Reorder the selection made in Ab6314s00 table.
	 *
	 * @param filterAb6314s00
	 *            Ab6314s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return Object
	 */
	public Object reorderSelection(Modalidad filterAb6314s00, JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		return this.ab6314s00Dao.reorderSelection(filterAb6314s00, jqGridRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE JERARQUIA
	 */

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

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

}
