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

/**
 * Ab6333s00ServiceImpl  
 * 
 *  
 */

@Service(value = "zonaOcioService")
public class ZonaOcioServiceImpl implements ZonaOcioService {

	@Autowired
	private ZonaOcioDao ab6333s00Dao;

	/**
	 * Inserts a single row in the Ab6333s00 table.
	 *
	 * @param ab6333s00
	 *            Ab6333s00
	 * @return Ab6333s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public ZonaOcio add(ZonaOcio ab6333s00) {
		return this.ab6333s00Dao.add(ab6333s00);
	}

	/**
	 * Updates a single row in the Ab6333s00 table.
	 *
	 * @param ab6333s00
	 *            Ab6333s00
	 * @return Ab6333s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public ZonaOcio update(ZonaOcio ab6333s00) {
		return this.ab6333s00Dao.update(ab6333s00);
	}

	/**
	 * Finds a single row in the Ab6333s00 table.
	 *
	 * @param ab6333s00
	 *            Ab6333s00
	 * @return Ab6333s00
	 */
	public ZonaOcio find(ZonaOcio ab6333s00) {
		return (ZonaOcio) this.ab6333s00Dao.find(ab6333s00);
	}

	/**
	 * Deletes a single row in the Ab6333s00 table.
	 *
	 * @param ab6333s00
	 *            Ab6333s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public void remove(ZonaOcio ab6333s00) {
		this.ab6333s00Dao.remove(ab6333s00);
	}

	/**
	 * Finds a list of rows in the Ab6333s00 table.
	 *
	 * @param ab6333s00
	 *            Ab6333s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @return List<Ab6333s00>
	 */
	public List<ZonaOcio> findAll(ZonaOcio ab6333s00, TableRequestDto tableRequestDto) {
		return (List<ZonaOcio>) this.ab6333s00Dao.findAll(ab6333s00, tableRequestDto);
	}

	/**
	 * Finds rows in the Ab6333s00 table using like.
	 *
	 * @param ab6333s00
	 *            Ab6333s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<Ab6333s00>
	 */
	public List<ZonaOcio> findAllLike(ZonaOcio ab6333s00, TableRequestDto tableRequestDto, Boolean startsWith) {
		return (List<ZonaOcio>) this.ab6333s00Dao.findAllLike(ab6333s00, tableRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE
	 */

	/**
	 * Removes rows from the Ab6333s00 table.
	 *
	 * @param filterAb6333s00
	 *            Ab6333s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 */
	public void removeMultiple(ZonaOcio filterAb6333s00, TableRequestDto tableRequestDto, Boolean startsWith) {
		this.ab6333s00Dao.removeMultiple(filterAb6333s00, tableRequestDto, startsWith);
	}

	/**
	 * Filter method in the Ab6333s00 table.
	 *
	 * @param filterAb6333s00
	 *            Ab6333s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return JQGridResponseDto<Ab6333s00>
	 */
	public TableResponseDto<ZonaOcio> filter(ZonaOcio filterAb6333s00, TableRequestDto tableRequestDto,
			Boolean startsWith) {

		List<ZonaOcio> listaAb6333s00 = this.ab6333s00Dao.findAllLike(filterAb6333s00, tableRequestDto, false);

		/*
		 * for (ZonaOcio zonaOcio : listaAb6333s00) {
		 * 
		 * /*if (null != zonaOcio.getTipoZonaOcio() &&
		 * !"".equals(zonaOcio.getTipoZonaOcio().getIdTipoZonaOcio())) {
		 * 
		 * if (LocaleContextHolder.getLocale().getLanguage().equalsIgnoreCase(
		 * Constantes.CASTELLANO)) {
		 * zonaOcio.setDescTipoZonaOcio(zonaOcio.getTipoZonaOcio().getDescTipoEs
		 * ()); } else {
		 * zonaOcio.setDescTipoZonaOcio(zonaOcio.getTipoZonaOcio().getDescTipoEu
		 * ()); } }
		 * 
		 * }
		 */
		Long recordNum = this.ab6333s00Dao.findAllLikeCount(filterAb6333s00 != null ? filterAb6333s00 : new ZonaOcio(),
				false);
		if (tableRequestDto.getMultiselection().getSelectedIds() != null) {
			List<TableRowDto<ZonaOcio>> reorderSelection = this.ab6333s00Dao.reorderSelection(filterAb6333s00,
					tableRequestDto, startsWith);
			return new TableResponseDto<ZonaOcio>(tableRequestDto, recordNum, listaAb6333s00, reorderSelection);
		}
		return new TableResponseDto<ZonaOcio>(tableRequestDto, recordNum, listaAb6333s00);
	}

	/**
	 * Searches rows in the Ab6333s00 table.
	 *
	 * @param filterAb6333s00
	 *            Ab6333s00
	 * @param searchAb6333s00
	 *            Ab6333s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<TableRowDto<Ab6333s00>>
	 */
	public List<TableRowDto<ZonaOcio>> search(ZonaOcio filterAb6333s00, ZonaOcio searchAb6333s00,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		return this.ab6333s00Dao.search(filterAb6333s00, searchAb6333s00, tableRequestDto, startsWith);
	}

	/**
	 * Reorder the selection made in Ab6333s00 table.
	 *
	 * @param filterAb6333s00
	 *            Ab6333s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return Object
	 */
	public Object reorderSelection(ZonaOcio filterAb6333s00, TableRequestDto tableRequestDto, Boolean startsWith) {
		return this.ab6333s00Dao.reorderSelection(filterAb6333s00, tableRequestDto, startsWith);
	}

	@Override
	@Transactional(rollbackFor = Throwable.class)
	public ZonaOcio save(ZonaOcio ab6333s00) {
		if (null != ab6333s00.getIdZonaOcio() && ab6333s00.getIdZonaOcio() > 0) {
			return this.update(ab6333s00);
		} else {
			return this.add(ab6333s00);
		}
	}

}
