package admin;
import java.util.Collection;
import java.util.List;

/**
 * UserDB is the repository of registered user information.  It is derived from
 * Section 2.6.1 of the requirements.
 */
public abstract class UserDB {

    /**
     * The collection of user data records.
     */
    Collection<UserRecord> data;

    /**
     * Reference to GroupDB needed for change and delete methods.
     */
    GroupDB groupDB;

    /**
     * Add the given UserRecord to the given UserDB.  The Id of the given user
     * record must not be the same as a user record already in the UserDB.
     * The Id component is required and must be eight characters or less.  The
     * email address is required.  The phone number is optional; if given, the
     * area code and number must be 3 and 7 digits respectively.
     */
    abstract void add(UserRecord ur);

    public class SE1 extends Exception {}
    public class SE2 extends Exception {}
    /**
     * Find a user by unique id.
     */
    abstract UserRecord findById(String id);

    /**
     * Find a user or users by real-world name.  If more than one is found,
     * the output list is sorted by id.
     */
    abstract List<UserRecord> findByName(String name);

    /**
     * Change the given old UserRecord to the given new record.  The old and
     * new records must not be the same.  The old record must already be in
     * the input db.  The new record must meet the same conditions as for the
     * input to the AddUser operation.  Typically the user runs the FindUser
     * operation prior to Change to locate an existing record to be changed.
     * 
     * If the user record id is changed, then change all occurrences of the
     * old id in the group db to the new id.
     */
    abstract void change(
        UserRecord old_ur, UserRecord new_ur);

    /**
     * Delete the given user record from the given UserDB.  The given record
     * must already be in the input db.  Typically the user runs the FindUser
     * operation prior to Delete to locate an existing record to delete.
     * 
     * In addition, delete the user from all groups of which the user is a
     * member.  If the deleted user is the only leader of a one more groups,
     * output a warning indicating that those groups have become leaderless.
     */
    abstract LeaderlessGroupsWarning delete(UserRecord ur);

}

/**
  * LeaderlessGroupsWarning is an secondary output of the UserDB.change and
  * UserDB.delete operations, indicating the names of zero or more groups that
  * have become leaderless as the result of a user having been deleted.
  */
abstract class LeaderlessGroupsWarning {
    Collection<String> groupNames;
}