package com.atlassian.bitbucket.internal.mirroring.mirror.auth;

import com.atlassian.bitbucket.permission.AbstractEffectivePermissionVisitor;
import com.atlassian.bitbucket.permission.EffectiveGlobalPermission;
import com.atlassian.bitbucket.permission.EffectiveProjectPermission;
import com.atlassian.bitbucket.permission.EffectiveRepositoryPermission;
import com.google.common.collect.Sets;

import java.util.Set;

/**
 * Collects the ids of projects and repositories for {@link EffectiveProjectPermission EffectiveProjectPermissions}
 * and {@link EffectiveRepositoryPermission EffectiveRepositoryPermissions}.
 */
public class ResourceIdCollectingPermissionVisitor extends AbstractEffectivePermissionVisitor<Void> {
    private Set<String> projectIds = Sets.newHashSet();
    private Set<String> repositoryIds = Sets.newHashSet();

    @Override
    public Void visit(EffectiveGlobalPermission permission) {
        return null;
    }

    @Override
    public Void visit(EffectiveRepositoryPermission permission) {
        repositoryIds.add(String.valueOf(permission.getRepositoryId()));
        return null;
    }

    @Override
    public Void visit(EffectiveProjectPermission permission) {
        projectIds.add(String.valueOf(permission.getProjectId()));
        return null;
    }

    public Set<String> getProjectIds() {
        return projectIds;
    }

    public Set<String> getRepositoryIds() {
        return repositoryIds;
    }
}
