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

/**
 * Ab6335s00ServiceImpl  
 * 
 *  
 */

@Service(value = "agenciaDataService")
public class AgenciaDataServiceImpl implements AgenciaDataService {

	@Autowired
	private AgenciaDataDao ab6335s00Dao;

	/**
	 * Inserts a single row in the Ab6335s00 table.
	 *
	 * @param ab6335s00
	 *            Ab6335s00
	 * @return Ab6335s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public AgenciaData add(AgenciaData ab6335s00) {
		return this.ab6335s00Dao.add(ab6335s00);
	}

	/**
	 * Updates a single row in the Ab6335s00 table.
	 *
	 * @param ab6335s00
	 *            Ab6335s00
	 * @return Ab6335s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public AgenciaData update(AgenciaData ab6335s00) {
		return this.ab6335s00Dao.update(ab6335s00);
	}

	/**
	 * Finds a single row in the Ab6335s00 table.
	 *
	 * @param ab6335s00
	 *            Ab6335s00
	 * @return Ab6335s00
	 */
	public AgenciaData find(AgenciaData ab6335s00) {
		return (AgenciaData) this.ab6335s00Dao.find(ab6335s00);
	}

	/**
	 * Deletes a single row in the Ab6335s00 table.
	 *
	 * @param ab6335s00
	 *            Ab6335s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public void remove(AgenciaData ab6335s00) {
		this.ab6335s00Dao.remove(ab6335s00);
	}

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

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

	/*
	 * OPERACIONES RUP_TABLE
	 */

	/**
	 * Removes rows from the Ab6335s00 table.
	 *
	 * @param filterAb6335s00
	 *            Ab6335s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 */
	public void removeMultiple(AgenciaData filterAb6335s00, JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		this.ab6335s00Dao.removeMultiple(filterAb6335s00, jqGridRequestDto, startsWith);
	}

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

	/**
	 * Searches rows in the Ab6335s00 table.
	 *
	 * @param filterAb6335s00
	 *            Ab6335s00
	 * @param searchAb6335s00
	 *            Ab6335s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<TableRowDto<Ab6335s00>>
	 */
	public List<TableRowDto<AgenciaData>> search(AgenciaData filterAb6335s00, AgenciaData searchAb6335s00,
			JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		return this.ab6335s00Dao.search(filterAb6335s00, searchAb6335s00, jqGridRequestDto, startsWith);
	}

	/**
	 * Reorder the selection made in Ab6335s00 table.
	 *
	 * @param filterAb6335s00
	 *            Ab6335s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return Object
	 */
	public Object reorderSelection(AgenciaData filterAb6335s00, JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		return this.ab6335s00Dao.reorderSelection(filterAb6335s00, jqGridRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE JERARQUIA
	 */

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

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

	@Override
	public String getNextNumCie() {
		return this.ab6335s00Dao.getNextNumCie();
	}

	@Override
	public int updateNumCieAgenciaData(AgenciaData agenciaData, String numCie) {
		return this.ab6335s00Dao.updateNumCieAgenciaData(agenciaData, numCie);
	}

	@Override
	public String getOrigenOficinaPpal(String idInstalOficinaPpal) {
		return this.ab6335s00Dao.getOrigenOficinaPpal(idInstalOficinaPpal);
	}

	@Override
	public Integer comprobarPrimeraSucursal(Integer idOficinaPpal, Integer idEstablecimiento) {
		return this.ab6335s00Dao.comprobarPrimeraSucursal(idOficinaPpal, idEstablecimiento);
	}

}
