package com.atlassian.stash.internal.user;

import com.atlassian.bitbucket.user.AbstractApplicationUserVisitor;
import com.atlassian.bitbucket.user.DetailedUser;
import com.atlassian.bitbucket.user.ServiceUser;
import com.atlassian.bitbucket.user.ApplicationUser;

import javax.annotation.Nonnull;

public class InternalUserUtils {

    private static final AbstractApplicationUserVisitor<Boolean> IS_INTERNAL_USER = new AbstractApplicationUserVisitor<Boolean>() {
        @Override
        public Boolean visit(@Nonnull DetailedUser user) {
            return user instanceof InternalDetailedUser;
        }

        @Override
        public Boolean visit(@Nonnull ServiceUser user) {
            return user instanceof InternalServiceUser;
        }

        @Override
        public Boolean visit(@Nonnull ApplicationUser user) {
            return user instanceof InternalApplicationUser;
        }
    };

    public static boolean isInternalUser(ApplicationUser user) {
        return user != null && user.accept(IS_INTERNAL_USER);
    }
}
