package eu.dnetlib.uoaadmintools;

import eu.dnetlib.uoaadmintools.dao.*;
import eu.dnetlib.uoaadmintools.entities.Community;
import eu.dnetlib.uoaadmintools.entities.Notifications;
import eu.dnetlib.uoaadmintools.entities.Page;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class NotificationsTests {

	@Autowired
	private CommunityDAO communityDAO;


	@Autowired
	private NotificationsDAO notificationsDAO;

	@Test
	public void test() {
		String mail = "sofie.mpl@gmail.com";
		String id="ni";
			System.out.println(notificationsDAO.findByCommunityPid(id));

		Notifications notifications = notificationsDAO.findByManagerEmailAndCommunityPid(mail	, id);
		if(notifications == null){
			notifications = new Notifications();
			notifications.setCommunityPid(id);
			notifications.setManagerEmail(mail);
		}
		notifications.setNotifyForNewManagers(false);
		notifications.setNotifyForNewSubscribers(false);

		notificationsDAO.save(notifications);
		System.out.println(notificationsDAO.findByCommunityPid(id));




	}

	@Test
	public void remove() {
		List <Community> communities = communityDAO.findAll();
		for(Community com : communities){
			List <Notifications> notificationsList = notificationsDAO.findByCommunityPid(com.getPid());
			for(Notifications notifications:notificationsList){
//				notificationsDAO.delete(notifications.getId());
			}
		}

	}

}
