package com.atlassian.stash.internal.liquibase;

import liquibase.change.custom.CustomChange;
import liquibase.database.Database;
import liquibase.exception.SetupException;
import liquibase.exception.ValidationErrors;
import liquibase.resource.ResourceAccessor;

import static com.google.common.base.Preconditions.checkArgument;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

/**
 * An abstract implementation of {@link CustomChange} to remove boilerplate from implementations
 */
public abstract class AbstractCustomChange implements CustomChange {

    protected static final int MAX_BATCH_SIZE = 25;
    protected static final int MAX_IN_CLAUSE_SIZE = 100;

    protected ResourceAccessor resourceAccessor;

    @Override
    public void setFileOpener(ResourceAccessor resourceAccessor) {
        this.resourceAccessor = resourceAccessor;
    }

    @Override
    public void setUp() throws SetupException {
    }

    @Override
    public ValidationErrors validate(Database database) {
        return new ValidationErrors();
    }

    protected void notBlank(String value, String name) {
        checkArgument(isNotBlank(value), "The %s parameter is required", name);
    }
}
