package com.atlassian.bitbucket.mesh.repository;

import javax.annotation.Nonnull;

/**
 * Abstract base class of {@link RepositoryVisitor} that supports concrete {@link Repository} implementation classes.
 *
 * @param <T> the visitor return type
 */
abstract class ConcreteRepositoryVisitor<T> implements RepositoryVisitor<T> {

    @Override
    public final T visit(@Nonnull BitbucketServerRepository repository) {
        if (repository instanceof DefaultBitbucketServerRepository) {
            return visit((DefaultBitbucketServerRepository) repository);
        }
        return defaultValue(repository);
    }

    @Override
    public T visit(@Nonnull ManagedRepository repository) {
        if (repository instanceof DefaultManagedRepository) {
            return visit((DefaultManagedRepository) repository);
        }
        return defaultValue(repository);
    }

    @Override
    public T visit(@Nonnull PathRepository repository) {
        if (repository instanceof DefaultPathRepository) {
            return visit((DefaultPathRepository) repository);
        }
        return defaultValue(repository);
    }

    @Override
    public T visit(@Nonnull SharedObjectsRepository repository) {
        if (repository instanceof DefaultSharedObjectsRepository) {
            return visit((DefaultSharedObjectsRepository) repository);
        }
        return defaultValue(repository);
    }

    public T visit(@Nonnull WorkTree workTree) {
        if (workTree instanceof DefaultWorkTree) {
            return visit((DefaultWorkTree) workTree);
        }
        return defaultValue(workTree);
    }

    T visit(@Nonnull DefaultBitbucketServerRepository repository) {
        return defaultValue(repository);
    }

    T visit(@Nonnull DefaultManagedRepository repository) {
        return defaultValue(repository);
    }

    T visit(@Nonnull DefaultPathRepository repository) {
        return defaultValue(repository);
    }

    T visit(@Nonnull DefaultSharedObjectsRepository repository) {
        return defaultValue(repository);
    }

    T visit(@Nonnull DefaultWorkTree workTree) {
        return defaultValue(workTree);
    }
}
