package com.bizzan.bitrade.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bizzan.bitrade.dao.AgentInfoDao;
import com.bizzan.bitrade.entity.AgentInfo;
import com.querydsl.core.types.Predicate;

@Service
public class AgentInfoService {

	@Autowired
	private AgentInfoDao dao;
	
	public AgentInfo findOne(Long id) {
		AgentInfo agentInfo = dao.findOne(id);
		if(agentInfo == null) {
			agentInfo = new AgentInfo();
			agentInfo.setId(id);
			agentInfo.setName("");
			agentInfo.setPhone("");
			agentInfo.setAddress("");
		}
		return agentInfo;
	}
	
	public void save(AgentInfo agentInfo) {
		dao.save(agentInfo);
	}
	
	public Page<AgentInfo> findAll(Predicate predicate, Pageable pageable) {
        return dao.findAll(predicate, pageable);
    }
	
	@Transactional(rollbackFor = Exception.class)
    public void deleteBatch(Long[] array) {
        for (Long serialNumber : array) {
        	dao.delete(serialNumber);
        }
    }
}
