package com.atlassian.bitbucket.content;

import javax.annotation.Nonnull;

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

public class SimpleConflictChange implements ConflictChange {

    private final Path path;
    private final Path srcPath;
    private final ChangeType type;

    private SimpleConflictChange(ChangeType type, Path path, Path srcPath) {
        this.path = checkNotNull(path, "path");
        this.srcPath = srcPath;
        this.type = checkNotNull(type, "type");
    }

    @Nonnull
    @Override
    public Path getPath() {
        return path;
    }

    @Override
    public Path getSrcPath() {
        return srcPath;
    }

    @Nonnull
    @Override
    public ChangeType getType() {
        return type;
    }

    public static class Builder {

        private Path path;
        private Path srcPath;
        private ChangeType type;

        public Builder() {
        }

        public Builder(ConflictChange change) {
            path = change.getPath();
            srcPath = change.getSrcPath();
            type = change.getType();
        }

        public SimpleConflictChange build() {
            checkState(path != null, "A path is required");
            checkState(type != null, "A type is required");

            return new SimpleConflictChange(type, path, srcPath);
        }

        public Builder path(Path value) {
            path = checkNotNull(value, "path");

            return this;
        }

        public Builder path(String value) {
            return path(new SimplePath(checkNotNull(value, "path")));
        }

        public Builder srcPath(Path value) {
            srcPath = value;

            return this;
        }

        public Builder srcPath(String value) {
            return srcPath(value == null ? null : new SimplePath(value));
        }

        public Builder type(ChangeType value) {
            type = checkNotNull(value, "type");

            return this;
        }
    }
}
