package com.eyrolles.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.eyrolles.model.Client;
import com.eyrolles.repository.ClientRepository;
import com.eyrolles.util.Crypt;

@Service
public class ClientService implements IClientService{
	
	@Autowired
	ClientRepository clientRepository;
	
	@Override
	public Client authentificate(String mail, String password) {
		List<Client> clients=clientRepository.findAll();
		for(Client c:clients){
			if(c.getEmail().equals(mail)&&c.getMotDePasse().equals(Crypt.encryptPassword(password)))
				return c;
		}
		return null;
	}

	@Override
	public Client create(Client c) {
		return clientRepository.save(c);
	}

	@Override
	public Client find(int id) {
		return clientRepository.findOne(id);
	}
	
}
