package com.atlassian.bitbucket.internal.ssh;

import com.atlassian.bitbucket.ssh.SshKey;
import com.atlassian.bitbucket.ssh.SshKeyService;
import com.atlassian.bitbucket.user.ApplicationUser;

import javax.annotation.Nonnull;

public interface InternalSshKeyService extends SshKeyService {

    /**
     * Checks whether the currently authenticated user has sufficient permissions to edit (add / create / delete)
     * SSH keys for the provided user.
     *
     * @param user the user for whom the current user wants to change keys. Cannot be null.
     * @return {@code true} if the current user has sufficient permissions
     */
    boolean canEditSshKeyForUser(@Nonnull ApplicationUser user);

    /**
     * Checks whether any projects or repositories reference the specified {@link ApplicationUser} and, if there are none,
     * removes the provided {@link SshKey}.
     *
     * @param key  the key to remove if the user is unreferenced
     * @param user the user to check permissions for
     * @return {@code true} if the key was removed; otherwise, {@code false}
     * @since 3.10
     */
    boolean removeIfOrphaned(@Nonnull SshKey key, @Nonnull ApplicationUser user);
}
