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.CategoriaDao;
import com.ejie.ab63.model.Categoria;
import com.ejie.x38.dto.JQGridRequestDto;
import com.ejie.x38.dto.JQGridResponseDto;
import com.ejie.x38.dto.JerarquiaDto;
import com.ejie.x38.dto.TableRequestDto;
import com.ejie.x38.dto.TableResponseDto;
import com.ejie.x38.dto.TableRowDto;

/**
 * Ab6313s00ServiceImpl  
 * 
 *  
 */

@Service(value = "categoriaService")
public class CategoriaServiceImpl implements CategoriaService {

	@Autowired
	private CategoriaDao ab6313s00Dao;

	/**
	 * Inserts a single row in the Ab6313s00 table.
	 *
	 * @param ab6313s00
	 *            Ab6313s00
	 * @return Ab6313s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public Categoria add(Categoria ab6313s00) {
		return this.ab6313s00Dao.add(ab6313s00);
	}

	/**
	 * Updates a single row in the Ab6313s00 table.
	 *
	 * @param ab6313s00
	 *            Ab6313s00
	 * @return Ab6313s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public Categoria update(Categoria ab6313s00) {
		return this.ab6313s00Dao.update(ab6313s00);
	}

	/**
	 * Finds a single row in the Ab6313s00 table.
	 *
	 * @param ab6313s00
	 *            Ab6313s00
	 * @return Ab6313s00
	 */
	public Categoria find(Categoria ab6313s00) {
		return (Categoria) this.ab6313s00Dao.find(ab6313s00);
	}

	/**
	 * Deletes a single row in the Ab6313s00 table.
	 *
	 * @param ab6313s00
	 *            Ab6313s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public void remove(Categoria ab6313s00) {
		this.ab6313s00Dao.remove(ab6313s00);
	}

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

	/**
	 * Finds rows in the Ab6313s00 table using like.
	 *
	 * @param ab6313s00
	 *            Ab6313s00
	 * @param tableRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<Ab6313s00>
	 */
	public List<Categoria> findAllLike(Categoria ab6313s00, TableRequestDto tableRequestDto, Boolean startsWith) {
		return (List<Categoria>) this.ab6313s00Dao.findAllLike(ab6313s00, tableRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE
	 */

	/**
	 * Removes rows from the Ab6313s00 table.
	 *
	 * @param filterAb6313s00
	 *            Ab6313s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 */
	public void removeMultiple(Categoria filterAb6313s00, JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		this.ab6313s00Dao.removeMultiple(filterAb6313s00, jqGridRequestDto, startsWith);
	}

	/**
	 * Filter method in the Ab6313s00 table.
	 *
	 * @param filterAb6313s00
	 *            Ab6313s00
	 * @param tableRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return JQGridResponseDto<Ab6313s00>
	 */
	public TableResponseDto<Categoria> filter(Categoria filterAb6313s00, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		List<Categoria> listaAb6313s00 = this.ab6313s00Dao.findAllLike(filterAb6313s00, tableRequestDto, false);
		Long recordNum = this.ab6313s00Dao.findAllLikeCount(filterAb6313s00 != null ? filterAb6313s00 : new Categoria(),
				false);
		if (tableRequestDto.getMultiselection().getSelectedIds() != null) {
			List<TableRowDto<Categoria>> reorderSelection = this.ab6313s00Dao.reorderSelection(filterAb6313s00,
					tableRequestDto, startsWith);
			return new TableResponseDto<Categoria>(tableRequestDto, recordNum, listaAb6313s00, reorderSelection);
		}
		return new TableResponseDto<Categoria>(tableRequestDto, recordNum, listaAb6313s00);
	}

	/**
	 * Searches rows in the Ab6313s00 table.
	 *
	 * @param filterAb6313s00
	 *            Ab6313s00
	 * @param searchAb6313s00
	 *            Ab6313s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<TableRowDto<Ab6313s00>>
	 */
	public List<TableRowDto<Categoria>> search(Categoria filterAb6313s00, Categoria searchAb6313s00,
			JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		return this.ab6313s00Dao.search(filterAb6313s00, searchAb6313s00, jqGridRequestDto, startsWith);
	}

	/**
	 * Reorder the selection made in Ab6313s00 table.
	 *
	 * @param filterAb6313s00
	 *            Ab6313s00
	 * @param tableRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return Object
	 */
	public Object reorderSelection(Categoria filterAb6313s00, TableRequestDto tableRequestDto, Boolean startsWith) {
		return this.ab6313s00Dao.reorderSelection(filterAb6313s00, tableRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE JERARQUIA
	 */

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

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

}
