/*
 * LinShare is an open source filesharing software, part of the LinPKI software
 * suite, developed by Linagora.
 * 
 * Copyright (C) 2013 LINAGORA
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any
 * later version, provided you comply with the Additional Terms applicable for
 * LinShare software by Linagora pursuant to Section 7 of the GNU Affero General
 * Public License, subsections (b), (c), and (e), pursuant to which you must
 * notably (i) retain the display of the “LinShare™” trademark/logo at the top
 * of the interface window, the display of the “You are using the Open Source
 * and free version of LinShare™, powered by Linagora © 2009–2013. Contribute to
 * Linshare R&D by subscribing to an Enterprise offer!” infobox and in the
 * e-mails sent with the Program, (ii) retain all hypertext links between
 * LinShare and linshare.org, between linagora.com and Linagora, and (iii)
 * refrain from infringing Linagora intellectual property rights over its
 * trademarks and commercial brands. Other Additional Terms apply, see
 * <http://www.linagora.com/licenses/> for more details.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Affero General Public License and
 * its applicable Additional Terms for LinShare along with this program. If not,
 * see <http://www.gnu.org/licenses/> for the GNU Affero General Public License
 * version 3 and <http://www.linagora.com/licenses/> for the Additional Terms
 * applicable to LinShare software.
 */
package org.linagora.linshare.core.service;

import java.io.IOException;
import java.util.List;

import javax.naming.NamingException;

import org.linagora.linshare.core.domain.entities.AbstractDomain;
import org.linagora.linshare.core.domain.entities.GuestDomain;
import org.linagora.linshare.core.domain.entities.RootDomain;
import org.linagora.linshare.core.domain.entities.SubDomain;
import org.linagora.linshare.core.domain.entities.TopDomain;
import org.linagora.linshare.core.domain.entities.User;
import org.linagora.linshare.core.exception.BusinessException;

public interface AbstractDomainService {
	
	public TopDomain createTopDomain(TopDomain topDomain) throws BusinessException;
	public SubDomain createSubDomain(SubDomain subDomain) throws BusinessException;
	public GuestDomain createGuestDomain(GuestDomain guestDomain) throws BusinessException;
	
	public AbstractDomain retrieveDomain(String identifier) throws BusinessException;
	public void updateDomain(AbstractDomain domain) throws BusinessException;
	public void deleteDomain(String identifier) throws BusinessException;
	public List<String> getAllDomainIdentifiers();
	public List<String> getAllMyDomainIdentifiers(String personalDomainIdentifer);
	
	
	/**
	 * This method returns all domain except the root domain.
	 * @return AbstractDomain list
	 * @throws BusinessException
	 */
	public List<AbstractDomain> getAllDomains();
	public List<AbstractDomain> getAllTopAndSubDomain();
	public List<AbstractDomain> getAllTopDomain();
	public List<AbstractDomain> getAllSubDomain();
	public GuestDomain getGuestDomain(String topDomainIdentifier);
	
	
	
	public RootDomain getUniqueRootDomain()throws BusinessException;
	
	/**
	 * This method returns a list containing all the authorized domains for the input domain.
	 * This used to filter communications between domains.
	 * @param domain identifier
	 * @return List of domains.
	 */
	public List<AbstractDomain> getAllAuthorizedDomains(String domainIdentifier);
	/**
	 * This method is designed to search in a particular domain and its SubDomain.
	 * @param domainIdentifier
	 * @param mail
	 * @return An user object List (Ldap entry) containing directory informations. (mail, first name and last name). It is not an entity !
	 * @throws BusinessException
	 */
	public List<User> searchUserWithDomainPolicies(String domainIdentifier, String mail, String firstName, String lastName) throws BusinessException;
	/**
	 * This method is designed to search in all existing domains.
	 * @param mail
	 * @param firstName
	 * @param lastName
	 * @return An user object (Ldap entry) containing directory informations. (mail, first name and last name). It is not an entity !
	 * @throws BusinessException
	 */
	public List<User> searchUserRecursivelyWithoutRestriction(String mail, String firstName, String lastName) throws BusinessException;
	
	/**
	 * This method is designed to search in a particular domain and its SubDomain.
	 * @param domainIdentifier
	 * @param mail
	 * @return An user object List (Ldap entry) containing directory informations. (mail, first name and last name). It is not an entity !
	 * @throws BusinessException
	 */
	public List<User> searchUserRecursivelyWithoutRestriction(String domainIdentifier, String mail, String firstName, String lastName) throws BusinessException;
	
	
	/**
	 * This method is designed to search users in a particular domain.
	 * @param domainIdentifier
	 * @param mail
	 * @return An user object List (Ldap entry) containing directory informations. (mail, first name, last name, domain and default role). It is not an entity !
	 * @throws BusinessException
	 */
	public List<User> searchUserWithoutRestriction(AbstractDomain domain, String mail, String firstName, String lastName) throws BusinessException;
	
	
	
	/**
	 * This method is designed to search in a particular domain and its SubDomain.
	 * @param domainIdentifier
	 * @param mail
	 * @return An user object (Ldap entry) containing directory informations. (mail, first name and last name). It is not an entity !
	 * @throws BusinessException
	 */
	public User searchOneUserRecursivelyWithoutRestriction(String domainIdentifier, String mail) throws BusinessException;
	
	public User auth(AbstractDomain domain,	String login, String password) throws BusinessException, NamingException, IOException;
	
	public boolean userCanCreateGuest(User user);
	public boolean canCreateGuestDomain(AbstractDomain domain) ;
	public boolean hasRightsToShareWithExternals(User sender) throws BusinessException;
	
	/**
	 * Retrieve the mail address for notifications (smtp sender)
	 * @param domain
	 * @return the mail
	 */
	public String getDomainMail(AbstractDomain domain);
}
