package com.atlassian.stash.internal.user;

import com.atlassian.stash.internal.Dao;

import javax.annotation.Nonnull;

public interface GrantedPermissionDao<E extends InternalGrantedPermission> extends Dao<Long, E> {

    /**
     * Checks for existence of the given permission.
     *
     * @param grantedPermission the permission to check.
     * @return true if the permission is currently granted, explicitly.
     */
    boolean hasPermissionEntry(@Nonnull E grantedPermission);

    /**
     * Revokes all the permissions of type {@code <E>} explicitly associated with an user.
     *
     * @param userId id identifying the user
     * @return count of the number of rows deleted
     */
    int revokeAll(int userId);

    /**
     * Revokes all the permissions  of type {@code <E>} explicitly associated with a group.
     *
     * @param groupName name of the group
     * @return count of the number of rows deleted
     */
    int revokeAll(@Nonnull String groupName);

    /**
     * Revokes the matching explicit permission(s)  of type {@code <E>}.
     *
     * @param grantedPermission the granted permission
     * @return count of the number of rows deleted
     */
    int revoke(@Nonnull E grantedPermission);

}
