package com.atlassian.bitbucket.home;

import javax.annotation.Nonnull;

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

public class SimpleHomeUpdate implements HomeUpdate {

    private final String newDir;
    private final String oldDir;

    private SimpleHomeUpdate(String newDir, String oldDir) {
        this.newDir = newDir;
        this.oldDir = oldDir;
    }

    @Nonnull
    @Override
    public String getNewDir() {
        return newDir;
    }

    @Nonnull
    @Override
    public String getOldDir() {
        return oldDir;
    }

    public static class Builder {

        private String newDir;
        private String oldDir;

        public Builder() {
        }

        public Builder(@Nonnull HomeUpdate update) {
            newDir = checkNotNull(update, "update").getNewDir();
            oldDir = update.getOldDir();
        }

        @Nonnull
        public SimpleHomeUpdate build() {
            checkNotNull(newDir, "newDir");
            checkNotNull(oldDir, "oldDir");

            return new SimpleHomeUpdate(newDir, oldDir);
        }

        @Nonnull
        public Builder newDir(@Nonnull String value) {
            newDir = checkNotNull(value, "value");

            return this;
        }

        @Nonnull
        public Builder oldDir(@Nonnull String value) {
            oldDir = checkNotNull(value, "value");

            return this;
        }
    }
}
