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

import com.atlassian.bitbucket.internal.mirroring.user.ApplicationUserWithPermissions;
import com.atlassian.bitbucket.internal.mirroring.user.ApplicationUserWithPermissionsVisitor;
import com.atlassian.bitbucket.permission.EffectivePermission;
import com.atlassian.bitbucket.user.ApplicationUserVisitor;
import com.atlassian.bitbucket.user.TestApplicationUser;
import com.google.common.collect.Lists;

import javax.annotation.Nonnull;
import java.util.Collections;

public class TestApplicationUserWithPermissions extends TestApplicationUser implements ApplicationUserWithPermissions {
    private final Iterable<EffectivePermission> effectivePermissions;

    public TestApplicationUserWithPermissions(String name, Integer id, Iterable<EffectivePermission> effectivePermissions) {
        super(name, id);
        this.effectivePermissions = Collections.unmodifiableList(Lists.newArrayList(effectivePermissions));
    }

    @Nonnull
    @Override
    public Iterable<EffectivePermission> getEffectivePermissions() {
        return effectivePermissions;
    }

    @Override
    public <T> T accept(@Nonnull ApplicationUserVisitor<T> visitor) {
        if (visitor instanceof ApplicationUserWithPermissionsVisitor) {
            return ((ApplicationUserWithPermissionsVisitor<T>) visitor).visit(this);
        }

        return super.accept(visitor);
    }
}
