package com.atlassian.stash.internal.backup.liquibase;

import liquibase.change.ColumnConfig;
import liquibase.change.core.DeleteDataChange;
import liquibase.change.core.InsertDataChange;
import liquibase.changelog.ChangeSet;

import java.util.Date;

public class LiquibaseChangeSetTestUtils {

    private LiquibaseChangeSetTestUtils() {
        // utility class
    }

    public static ChangeSet newChangeSet(String id, String author, String context, String dbms) {
        return new ChangeSet(id, author, false, false, "liquibase-stash-tests.xml", context, dbms, false);
    }

    public static DeleteDataChange newDeleteChange(String tableName) {
        DeleteDataChange delete = new DeleteDataChange();
        delete.setTableName(tableName);
        return delete;
    }

    public static InsertDataChange newInsertChange(String tableName, ColumnConfig... columns) {
        InsertDataChange insert = new InsertDataChange();
        insert.setTableName(tableName);
        for (ColumnConfig column : columns) {
            insert.addColumn(column);
        }
        return insert;
    }

    public static ColumnConfig newColumnConfig(String name, String value) {
        ColumnConfig columnConfig = new ColumnConfig().setName(name);
        columnConfig.setValue(value);
        return columnConfig;
    }

    public static ColumnConfig newColumnConfig(String name, boolean value) {
        return new ColumnConfig().setName(name).setValueBoolean(value);
    }

    public static ColumnConfig newColumnConfig(String name, Number value) {
        return new ColumnConfig().setName(name).setValueNumeric(value);
    }

    public static ColumnConfig newColumnConfig(String name, Date value) {
        return new ColumnConfig().setName(name).setValueDate(value);
    }

}
