package com.jpsoft.shinestar.modules.base.service.impl;

import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.jpsoft.shinestar.modules.base.dao.PersonPhoneBookDAO;
import com.jpsoft.shinestar.modules.base.entity.PersonPhoneBook;
import com.jpsoft.shinestar.modules.base.service.PersonPhoneBookService;
import com.github.pagehelper.Page;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.github.pagehelper.PageHelper;
import org.springframework.validation.annotation.Validated;

@Transactional
@Component(value="personPhoneBookService")
public class PersonPhoneBookServiceImpl implements PersonPhoneBookService {
	@Resource(name="personPhoneBookDAO")
	private PersonPhoneBookDAO personPhoneBookDAO;

	@Override
	public PersonPhoneBook get(String id) {
		// TODO Auto-generated method stub
		return personPhoneBookDAO.get(id);
	}

	@Validated
	@Override
	public int insert(@Valid PersonPhoneBook model) {
		// TODO Auto-generated method stub
		//model.setId(UUID.randomUUID().toString());
		
		return personPhoneBookDAO.insert(model);
	}

	@Validated
	@Override
	public int update(@Valid PersonPhoneBook model) {
		// TODO Auto-generated method stub
		return personPhoneBookDAO.update(model);		
	}

	@Override
	public int delete(String id) {
		// TODO Auto-generated method stub
		return personPhoneBookDAO.delete(id);
	}

	@Override
	public boolean exist(String id) {
		// TODO Auto-generated method stub
		int count = personPhoneBookDAO.exist(id);
		
		return count > 0 ? true : false;
	}
	
	@Override
	public List<PersonPhoneBook> list() {
		// TODO Auto-generated method stub
		return personPhoneBookDAO.list();
	}
		
	@Override
	public Page<PersonPhoneBook> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
        Page<PersonPhoneBook> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
            personPhoneBookDAO.search(searchParams,sortList);
        });
        
        return page;
	}

	@Override
	public List<PersonPhoneBook> findByPersonIdAndUrgent(Long personId,Boolean urgentStatus){
		return personPhoneBookDAO.findByPersonIdAndUrgent(personId,urgentStatus);
	}
}