package com.ejie.ab63.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ejie.ab63.comun.Constantes;
import com.ejie.ab63.dao.AseoAlojamientoDao;
import com.ejie.ab63.model.AseoAlojamiento;
import com.ejie.x38.dto.JQGridRequestDto;
import com.ejie.x38.dto.JQGridResponseDto;
import com.ejie.x38.dto.JerarquiaDto;
import com.ejie.x38.dto.TableRowDto;

/**
 * Ab6326s00ServiceImpl  
 * 
 *  
 */

@Service(value = "aseoAlojamientoService")
public class AseoAlojamientoServiceImpl implements AseoAlojamientoService {

	@Autowired
	private AseoAlojamientoDao ab6326s00Dao;

	/**
	 * Inserts a single row in the Ab6326s00 table.
	 *
	 * @param ab6326s00
	 *            Ab6326s00
	 * @return Ab6326s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public AseoAlojamiento add(AseoAlojamiento ab6326s00) {
		return this.ab6326s00Dao.add(ab6326s00);
	}

	/**
	 * Updates a single row in the Ab6326s00 table.
	 *
	 * @param ab6326s00
	 *            Ab6326s00
	 * @return Ab6326s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public AseoAlojamiento update(AseoAlojamiento ab6326s00) {
		return this.ab6326s00Dao.update(ab6326s00);
	}

	/**
	 * Finds a single row in the Ab6326s00 table.
	 *
	 * @param ab6326s00
	 *            Ab6326s00
	 * @return Ab6326s00
	 */
	public AseoAlojamiento find(AseoAlojamiento ab6326s00) {
		return (AseoAlojamiento) this.ab6326s00Dao.find(ab6326s00);
	}

	/**
	 * Deletes a single row in the Ab6326s00 table.
	 *
	 * @param ab6326s00
	 *            Ab6326s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public void remove(AseoAlojamiento ab6326s00) {
		this.ab6326s00Dao.remove(ab6326s00);
	}

	/**
	 * Finds a list of rows in the Ab6326s00 table.
	 *
	 * @param ab6326s00
	 *            Ab6326s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @return List<Ab6326s00>
	 */
	public List<AseoAlojamiento> findAll(AseoAlojamiento ab6326s00, JQGridRequestDto jqGridRequestDto) {
		return (List<AseoAlojamiento>) this.ab6326s00Dao.findAll(ab6326s00, jqGridRequestDto);
	}

	/**
	 * Finds rows in the Ab6326s00 table using like.
	 *
	 * @param ab6326s00
	 *            Ab6326s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<Ab6326s00>
	 */
	public List<AseoAlojamiento> findAllLike(AseoAlojamiento ab6326s00, JQGridRequestDto jqGridRequestDto,
			Boolean startsWith) {
		return (List<AseoAlojamiento>) this.ab6326s00Dao.findAllLike(ab6326s00, jqGridRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE
	 */

	/**
	 * Removes rows from the Ab6326s00 table.
	 *
	 * @param filterAb6326s00
	 *            Ab6326s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 */
	public void removeMultiple(AseoAlojamiento filterAb6326s00, JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		this.ab6326s00Dao.removeMultiple(filterAb6326s00, jqGridRequestDto, startsWith);
	}

	/**
	 * Filter method in the Ab6326s00 table.
	 *
	 * @param filterAb6326s00
	 *            Ab6326s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return JQGridResponseDto<Ab6326s00>
	 */
	public JQGridResponseDto<AseoAlojamiento> filter(AseoAlojamiento filterAb6326s00, JQGridRequestDto jqGridRequestDto,
			Boolean startsWith) {
		List<AseoAlojamiento> listaAb6326s00 = this.ab6326s00Dao.findAllLike(filterAb6326s00, jqGridRequestDto, false);

		for (AseoAlojamiento aseoAlojamiento : listaAb6326s00) {

			if (null != aseoAlojamiento.getTipoAseo() && !"".equals(aseoAlojamiento.getTipoAseo().getIdTipoAseo())) {

				if (LocaleContextHolder.getLocale().getLanguage().equalsIgnoreCase(Constantes.CASTELLANO)) {
					aseoAlojamiento.setDescTipoAseo(aseoAlojamiento.getTipoAseo().getDescTipoEs());
				} else {
					aseoAlojamiento.setDescTipoAseo(aseoAlojamiento.getTipoAseo().getDescTipoEu());
				}
			}

		}

		Long recordNum = this.ab6326s00Dao
				.findAllLikeCount(filterAb6326s00 != null ? filterAb6326s00 : new AseoAlojamiento(), false);
		if (jqGridRequestDto.getMultiselection().getSelectedIds() != null) {
			List<TableRowDto<AseoAlojamiento>> reorderSelection = this.ab6326s00Dao.reorderSelection(filterAb6326s00,
					jqGridRequestDto, startsWith);
			return new JQGridResponseDto<AseoAlojamiento>(jqGridRequestDto, recordNum, listaAb6326s00,
					reorderSelection);
		}
		return new JQGridResponseDto<AseoAlojamiento>(jqGridRequestDto, recordNum, listaAb6326s00);
	}

	/**
	 * Searches rows in the Ab6326s00 table.
	 *
	 * @param filterAb6326s00
	 *            Ab6326s00
	 * @param searchAb6326s00
	 *            Ab6326s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<TableRowDto<Ab6326s00>>
	 */
	public List<TableRowDto<AseoAlojamiento>> search(AseoAlojamiento filterAb6326s00, AseoAlojamiento searchAb6326s00,
			JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		return this.ab6326s00Dao.search(filterAb6326s00, searchAb6326s00, jqGridRequestDto, startsWith);
	}

	/**
	 * Reorder the selection made in Ab6326s00 table.
	 *
	 * @param filterAb6326s00
	 *            Ab6326s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return Object
	 */
	public Object reorderSelection(AseoAlojamiento filterAb6326s00, JQGridRequestDto jqGridRequestDto,
			Boolean startsWith) {
		return this.ab6326s00Dao.reorderSelection(filterAb6326s00, jqGridRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE JERARQUIA
	 */

	/**
	 * Finder method in the hierarchical the Ab6326s00 table.
	 *
	 * @param filterAb6326s00
	 *            Ab6326s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return JQGridResponseDto<JerarquiaDto<Ab6326s00>>
	 */
	public JQGridResponseDto<JerarquiaDto<AseoAlojamiento>> jerarquia(AseoAlojamiento filterAb6326s00,
			JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		List<JerarquiaDto<AseoAlojamiento>> listaAb6326s00 = this.ab6326s00Dao.findAllLikeJerarquia(filterAb6326s00,
				jqGridRequestDto);
		Long recordNum = this.ab6326s00Dao.findAllLikeCountJerarquia(filterAb6326s00, jqGridRequestDto);
		return new JQGridResponseDto<JerarquiaDto<AseoAlojamiento>>(jqGridRequestDto, recordNum, listaAb6326s00);
	}

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

	@Override
	public AseoAlojamiento save(AseoAlojamiento ab6326s00) {
		if (null != ab6326s00.getIdAseoAlo() && ab6326s00.getIdAseoAlo() > 0) {
			return this.update(ab6326s00);
		} else {
			return this.add(ab6326s00);
		}
	}

	@Override
	public void deleteByIdAlojamiento(Integer idAlojamiento) {
		this.ab6326s00Dao.deleteByIdAlojamiento(idAlojamiento);
	}

}
