package com.ejie.ab63.service.nora;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ejie.ab63.dao.nora.T17PortalDao;
import com.ejie.ab63.model.nora.T17Portal;
import com.ejie.x38.dto.Pagination;

/**
 * T17PortalServiceImpl  
 * 
 *  
 */
@Service(value = "t17PortalService")
public class T17PortalServiceImpl implements T17PortalService {
	/**
	 * Final static logger.
	 */
	private static final Logger logger = LoggerFactory.getLogger(T17PortalServiceImpl.class);

	@Autowired()
	private T17PortalDao t17PortalDao;

	/**
	 * Inserts a single row in the T17Portal table.
	 * 
	 * @param t17Portal
	 *            T17Portal
	 * @return T17Portal
	 */
	@Transactional(rollbackFor = Throwable.class)
	public T17Portal add(T17Portal t17Portal) {
		return this.t17PortalDao.add(t17Portal);
	}

	/**
	 * Updates a single row in the T17Portal table.
	 * 
	 * @param t17Portal
	 *            T17Portal
	 * @return T17Portal
	 */
	@Transactional(rollbackFor = Throwable.class)
	public T17Portal update(T17Portal t17Portal) {
		return this.t17PortalDao.update(t17Portal);
	}

	/**
	 * Finds a single row in the T17Portal table.
	 * 
	 * @param t17Portal
	 *            T17Portal
	 * @return T17Portal
	 */
	public T17Portal find(T17Portal t17Portal) {
		return (T17Portal) this.t17PortalDao.find(t17Portal);
	}

	/**
	 * Finds a List of rows in the T17Portal table.
	 * 
	 * @param t17Portal
	 *            T17Portal
	 * @param pagination
	 *            Pagination<Object>
	 * @return List
	 */
	public List<T17Portal> findAll(T17Portal t17Portal, Pagination<Object> pagination) {

		List<T17Portal> listPortal = this.t17PortalDao.findAll(t17Portal, pagination);

		for (T17Portal port : listPortal) {
			StringBuffer portal = new StringBuffer();

			portal.append(port.getNumero());

			if (port.getBis() != null && !port.getBis().equals("")) {
				portal.append("-").append(port.getBis());
			}

			port.setPortal(portal.toString());
		}

		return listPortal;
	}

	/**
	 * Counts rows in the T17Portal table.
	 * 
	 * @param t17Portal
	 *            T17Portal
	 * @return Long
	 */
	public Long findAllCount(T17Portal t17Portal) {
		return this.t17PortalDao.findAllCount(t17Portal);
	}

	/**
	 * Finds rows in the T17Portal table using like.
	 * 
	 * @param t17Portal
	 *            T17Portal
	 * @param pagination
	 *            Pagination<Object>
	 * @param startsWith
	 *            Boolean
	 * 
	 * @return List<T17Portal>
	 */
	public List<T17Portal> findAllLike(T17Portal t17Portal, Pagination<Object> pagination, Boolean startsWith) {
		return (List<T17Portal>) this.t17PortalDao.findAllLike(t17Portal, pagination, startsWith);
	}

	/**
	 * Deletes a single row in the T17Portal table.
	 * 
	 * @param t17Portal
	 *            T17Portal
	 */
	@Transactional(rollbackFor = Throwable.class)
	public void remove(T17Portal t17Portal) {
		this.t17PortalDao.remove(t17Portal);
	}

	/**
	 * Deletes multiple rows in the T17Portal table.
	 * 
	 * @param t17PortalList
	 *            ArrayList
	 */
	@Transactional(rollbackFor = Throwable.class)
	public void removeMultiple(ArrayList<T17Portal> t17PortalList) {
		for (T17Portal t17PortalAux : t17PortalList) {
			this.t17PortalDao.remove(t17PortalAux);
		}
	}

	/**
	 * 
	 * @return T17PortalDao
	 */
	public T17PortalDao getT17PortalDao() {
		return this.t17PortalDao;
	}

	/**
	 * 
	 * @param t17PortalDao
	 *            T17PortalDao
	 */
	public void setT17PortalDao(T17PortalDao t17PortalDao) {
		T17PortalServiceImpl.logger.info("Setting Dependency " + t17PortalDao);
		this.t17PortalDao = t17PortalDao;
	}

	/**
	 * Finds a List of distinct CP rows in the T17Portal table.
	 * 
	 * @param t17Portal
	 *            T17Portal
	 * @param pagination
	 *            Pagination<Object>
	 * @param startsWith
	 *            Boolean
	 * 
	 * @return List<T17Portal>
	 */
	public List<T17Portal> findAllLikeCodigoPostal(T17Portal t17Portal, Pagination<Object> pagination,
			Boolean startsWith) {
		return (List<T17Portal>) this.t17PortalDao.findAllLikeCodigoPostal(t17Portal, pagination, startsWith);
	}

	/**
	 * Finds a List of distinct CP rows in the T17Portal table.
	 * 
	 * @param t17Portal
	 *            T17Portal
	 * @return T17Portal
	 */
	public T17Portal findCodigoPostal(T17Portal t17Portal) {
		return (T17Portal) this.t17PortalDao.findCodigoPostal(t17Portal);
	}

	/**
	 * Finds a single row in the T17Portal table.
	 * 
	 * @param idT17portal
	 *            Long
	 * @return T17Portal
	 */
	public T17Portal find(Long idT17portal) {
		return (T17Portal) this.t17PortalDao.find(idT17portal);
	}
}
