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.TipoFranquiciaDao;
import com.ejie.ab63.model.TipoFranquicia;
import com.ejie.x38.dto.JerarquiaDto;
import com.ejie.x38.dto.TableRequestDto;
import com.ejie.x38.dto.TableResponseDto;
import com.ejie.x38.dto.TableRowDto;

/**
 * Ab6336s00ServiceImpl  
 * 
 *  
 */

@Service(value = "tipoFranquiciaService")
public class TipoFranquiciaServiceImpl implements TipoFranquiciaService {

	@Autowired
	private TipoFranquiciaDao ab6336s00Dao;

	/**
	 * Inserts a single row in the Ab6336s00 table.
	 *
	 * @param ab6336s00
	 *            Ab6336s00
	 * @return Ab6336s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public TipoFranquicia add(TipoFranquicia ab6336s00) {
		return this.ab6336s00Dao.add(ab6336s00);
	}

	/**
	 * Updates a single row in the Ab6336s00 table.
	 *
	 * @param ab6336s00
	 *            Ab6336s00
	 * @return Ab6336s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public TipoFranquicia update(TipoFranquicia ab6336s00) {
		return this.ab6336s00Dao.update(ab6336s00);
	}

	/**
	 * Finds a single row in the Ab6336s00 table.
	 *
	 * @param ab6336s00
	 *            Ab6336s00
	 * @return Ab6336s00
	 */
	public TipoFranquicia find(TipoFranquicia ab6336s00) {
		return (TipoFranquicia) this.ab6336s00Dao.find(ab6336s00);
	}

	/**
	 * Deletes a single row in the Ab6336s00 table.
	 *
	 * @param ab6336s00
	 *            Ab6336s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public void remove(TipoFranquicia ab6336s00) {
		this.ab6336s00Dao.remove(ab6336s00);
	}

	/**
	 * Finds a list of rows in the Ab6336s00 table.
	 *
	 * @param ab6336s00
	 *            Ab6336s00
	 * @param tableRequestDto
	 *            TableRequestDto
	 * @return List<Ab6336s00>
	 */
	public List<TipoFranquicia> findAll(TipoFranquicia ab6336s00, TableRequestDto tableRequestDto) {
		return (List<TipoFranquicia>) this.ab6336s00Dao.findAll(ab6336s00, tableRequestDto);
	}

	/**
	 * Finds rows in the Ab6336s00 table using like.
	 *
	 * @param ab6336s00
	 *            Ab6336s00
	 * @param tableRequestDto
	 *            TableRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<Ab6336s00>
	 */
	public List<TipoFranquicia> findAllLike(TipoFranquicia ab6336s00, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		return (List<TipoFranquicia>) this.ab6336s00Dao.findAllLike(ab6336s00, tableRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE
	 */

	/**
	 * Removes rows from the Ab6336s00 table.
	 *
	 * @param filterAb6336s00
	 *            Ab6336s00
	 * @param tableRequestDto
	 *            TableRequestDto
	 * @param startsWith
	 *            Boolean
	 */
	public void removeMultiple(TipoFranquicia filterAb6336s00, TableRequestDto tableRequestDto, Boolean startsWith) {
		this.ab6336s00Dao.removeMultiple(filterAb6336s00, tableRequestDto, startsWith);
	}

	/**
	 * Filter method in the Ab6336s00 table.
	 *
	 * @param filterAb6336s00
	 *            Ab6336s00
	 * @param tableRequestDto
	 *            TableRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return TableResponseDto<Ab6336s00>
	 */
	public TableResponseDto<TipoFranquicia> filter(TipoFranquicia filterAb6336s00, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		List<TipoFranquicia> listaAb6336s00 = this.ab6336s00Dao.findAllLike(filterAb6336s00, tableRequestDto, false);
		Long recordNum = this.ab6336s00Dao
				.findAllLikeCount(filterAb6336s00 != null ? filterAb6336s00 : new TipoFranquicia(), false);

		TableResponseDto<TipoFranquicia> usuarioDto = new TableResponseDto<TipoFranquicia>(tableRequestDto, recordNum,
				listaAb6336s00);

		if (tableRequestDto.getMultiselection().getSelectedIds() != null) {
			List<TableRowDto<TipoFranquicia>> reorderSelection = this.ab6336s00Dao.reorderSelection(filterAb6336s00,
					tableRequestDto, startsWith);
			usuarioDto.setReorderedSelection(reorderSelection);
			usuarioDto.addAdditionalParam("reorderedSelection", reorderSelection);
			usuarioDto.addAdditionalParam("selectedAll", tableRequestDto.getMultiselection().getSelectedAll());
		}
		if (tableRequestDto.getSeeker().getSelectedIds() != null) {
			tableRequestDto.setMultiselection(tableRequestDto.getSeeker());
			List<TableRowDto<TipoFranquicia>> reorderSeeker = this.ab6336s00Dao.reorderSelection(filterAb6336s00,
					tableRequestDto, startsWith);
			usuarioDto.setReorderedSeeker(reorderSeeker);
			usuarioDto.addAdditionalParam("reorderedSeeker", reorderSeeker);
		}
		return usuarioDto;
	}

	/**
	 * Searches rows in the Ab6336s00 table.
	 *
	 * @param filterAb6336s00
	 *            Ab6336s00
	 * @param searchAb6336s00
	 *            Ab6336s00
	 * @param tableRequestDto
	 *            TableRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<TableRowDto<Ab6336s00>>
	 */
	public List<TableRowDto<TipoFranquicia>> search(TipoFranquicia filterAb6336s00, TipoFranquicia searchAb6336s00,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		return this.ab6336s00Dao.search(filterAb6336s00, searchAb6336s00, tableRequestDto, startsWith);
	}

	/**
	 * Reorder the selection made in Ab6336s00 table.
	 *
	 * @param filterAb6336s00
	 *            Ab6336s00
	 * @param tableRequestDto
	 *            TableRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return Object
	 */
	public Object reorderSelection(TipoFranquicia filterAb6336s00, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		return this.ab6336s00Dao.reorderSelection(filterAb6336s00, tableRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE JERARQUIA
	 */

	/**
	 * Finder method in the hierarchical the Ab6336s00 table.
	 *
	 * @param filterAb6336s00
	 *            Ab6336s00
	 * @param tableRequestDto
	 *            TableRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return TableResponseDto<JerarquiaDto<Ab6336s00>>
	 */
	public TableResponseDto<JerarquiaDto<TipoFranquicia>> jerarquia(TipoFranquicia filterAb6336s00,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		List<JerarquiaDto<TipoFranquicia>> listaAb6336s00 = this.ab6336s00Dao.findAllLikeJerarquia(filterAb6336s00,
				tableRequestDto);
		Long recordNum = this.ab6336s00Dao.findAllLikeCountJerarquia(filterAb6336s00, tableRequestDto);
		return new TableResponseDto<JerarquiaDto<TipoFranquicia>>(tableRequestDto, recordNum, listaAb6336s00);
	}

	/**
	 * Finder method for siblings rows in the hierarchical the Ab6336s00 table.
	 *
	 * @param filterAb6336s00
	 *            Ab6336s00
	 * @param tableRequestDto
	 *            TableRequestDto
	 * @return TableResponseDto<JerarquiaDto<Ab6336s00>>
	 */
	public TableResponseDto<JerarquiaDto<TipoFranquicia>> jerarquiaChildren(TipoFranquicia filterAb6336s00,
			TableRequestDto tableRequestDto) {
		TableResponseDto<JerarquiaDto<TipoFranquicia>> tableResponseDto = new TableResponseDto<JerarquiaDto<TipoFranquicia>>();
		tableResponseDto.addAdditionalParam(TableResponseDto.CHILDREN,
				this.ab6336s00Dao.findAllChild(filterAb6336s00, tableRequestDto));
		return tableResponseDto;
	}

	/**
	 * Exporta Datos al clipBoard
	 *
	 */
	public List<TipoFranquicia> getMultiple(TipoFranquicia filterAb6336s00, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		return this.ab6336s00Dao.getMultiple(filterAb6336s00, tableRequestDto, startsWith);
	}

}
