package com.atlassian.stash.internal.db;

import com.atlassian.bitbucket.util.Version;

import javax.annotation.Nonnull;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * @since 2.2
 */
public class DelegatingDetailedDatabase implements DetailedDatabase {

    private final Database database;
    private final DatabaseSupportLevel supportLevel;
    private final DbType type;

    public DelegatingDetailedDatabase(Database database, DatabaseSupportLevel supportLevel, DbType type) {
        this.database = checkNotNull(database, "database");
        this.supportLevel = checkNotNull(supportLevel, "supportLevel");
        this.type = type;
    }

    @Override
    public int getMajorVersion() {
        return database.getMajorVersion();
    }

    @Override
    public int getMinorVersion() {
        return database.getMinorVersion();
    }

    @Override
    @Nonnull
    public String getName() {
        return database.getName();
    }

    @Override
    public int getPatchVersion() {
        return database.getPatchVersion();
    }

    @Nonnull
    @Override
    public DatabaseSupportLevel getSupportLevel() {
        return supportLevel;
    }

    @Override
    public DbType getType() {
        return type;
    }

    @Override
    @Nonnull
    public Version getVersion() {
        return database.getVersion();
    }

    @Override
    public boolean isClusterable() {
        return type != null && type.isClusterable();
    }

    @Override
    public boolean isInternal() {
        return DefaultDatabaseSupplier.NAME_H2.equals(getName()) ||
                DefaultDatabaseSupplier.NAME_HSQL.equals(getName());
    }
}
