package com.ejie.ab39a.service;

import com.ejie.ab39a.dao.AccionesDao;
import com.ejie.x38.dto.JQGridRequestDto;
import com.ejie.x38.dto.JQGridResponseDto;
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.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.ejie.ab39a.model.Acciones;

/**
 * Acciones.
 * 
 *  
 */
@Service(value = "accionesService")
public class AccionesServiceImpl implements AccionesService {

	@Autowired
	private AccionesDao accionesDao;

	/**
	 * Inserts a single row in the Acciones table.
	 *
	 * @param acciones
	 *            Acciones
	 * @return Acciones
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class)
	public Acciones add(Acciones acciones) {
		return this.accionesDao.add(acciones);
	}

	/**
	 * Updates a single row in the Acciones table.
	 *
	 * @param acciones
	 *            Acciones
	 * @return Acciones
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class)
	public Acciones update(Acciones acciones) {
		return this.accionesDao.update(acciones);
	}

	/**
	 * Finds a single row in the Acciones table.
	 *
	 * @param acciones
	 *            Acciones
	 * @return Acciones
	 */
	@Override
	@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED)
	public Acciones find(Acciones acciones) {
		return this.accionesDao.find(acciones);
	}

	/**
	 * Deletes a single row in the Acciones table.
	 *
	 * @param acciones
	 *            Acciones
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class)
	public void remove(Acciones acciones) {
		this.accionesDao.remove(acciones);
	}

	/**
	 * Finds a list of rows in the Acciones table.
	 *
	 * @param acciones
	 *            Acciones
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @return List<Acciones>
	 */
	@Override
	@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED)
	public List<Acciones> findAll(Acciones acciones, JQGridRequestDto jqGridRequestDto) {
		return this.accionesDao.findAll(acciones, jqGridRequestDto);
	}

	/**
	 * Finds rows in the Acciones table using like.
	 *
	 * @param acciones
	 *            Acciones
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<Acciones>
	 */
	@Override
	@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED)
	public List<Acciones> findAllLike(Acciones acciones, JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		return this.accionesDao.findAllLike(acciones, jqGridRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE
	 */

	/**
	 * Removes rows from the Acciones table.
	 *
	 * @param filterAcciones
	 *            Acciones
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class)
	public void removeMultiple(Acciones filterAcciones, JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		this.accionesDao.removeMultiple(filterAcciones, jqGridRequestDto, startsWith);
	}

	/**
	 * Filter method in the Acciones table.
	 *
	 * @param filterAcciones
	 *            Acciones
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return JQGridResponseDto<Acciones>
	 */
	@Override
	@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED)
	public JQGridResponseDto<Acciones> filter(Acciones filterAcciones, JQGridRequestDto jqGridRequestDto,
			Boolean startsWith) {
		List<Acciones> listaAcciones = this.accionesDao.findAllLike(filterAcciones, jqGridRequestDto, false);
		Long recordNum = this.accionesDao.findAllLikeCount(filterAcciones != null ? filterAcciones : new Acciones(),
				false);
		if (jqGridRequestDto.getMultiselection().getSelectedIds() != null) {
			List<TableRowDto<Acciones>> reorderSelection = this.accionesDao.reorderSelection(filterAcciones,
					jqGridRequestDto, startsWith);
			return new JQGridResponseDto<Acciones>(jqGridRequestDto, recordNum, listaAcciones, reorderSelection);
		}
		return new JQGridResponseDto<Acciones>(jqGridRequestDto, recordNum, listaAcciones);
	}

	/**
	 * Filter method in the Acciones table.
	 *
	 * @param filterAcciones
	 *            Acciones
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return JQGridResponseDto<Acciones>
	 */
	@Override
	@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED)
	public JQGridResponseDto<Acciones> buscarTablaAccionesPg(Acciones filterAcciones, JQGridRequestDto jqGridRequestDto,
			Boolean startsWith) {
		List<Acciones> listaAcciones = this.accionesDao.buscarTablaAccionesPg(filterAcciones, jqGridRequestDto, false);
		Long recordNum = this.accionesDao
				.buscarTablaAccionesPgCount(filterAcciones != null ? filterAcciones : new Acciones(), false);
		if (jqGridRequestDto.getMultiselection().getSelectedIds() != null) {
			List<TableRowDto<Acciones>> reorderSelection = this.accionesDao.reorderSelection(filterAcciones,
					jqGridRequestDto, startsWith);
			return new JQGridResponseDto<Acciones>(jqGridRequestDto, recordNum, listaAcciones, reorderSelection);
		}
		return new JQGridResponseDto<Acciones>(jqGridRequestDto, recordNum, listaAcciones);
	}

	/**
	 * Reorder the selection made in Acciones table.
	 *
	 * @param filterAcciones
	 *            Acciones
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return Object
	 */
	@Override
	@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED)
	public Object reorderSelection(Acciones filterAcciones, JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		return this.accionesDao.reorderSelection(filterAcciones, jqGridRequestDto, startsWith);
	}

}
