package com.atlassian.bitbucket.repository;

import javax.annotation.Nonnull;

import static com.atlassian.bitbucket.repository.StandardRefType.BRANCH;

public class SimpleBranch extends SimpleRef implements Branch {

    private final boolean isDefault;

    protected SimpleBranch(AbstractBranchBuilder<?, ?> builder) {
        super(builder, BRANCH);

        isDefault = builder.isDefault;
    }

    @Override
    public boolean getIsDefault() {
        return isDefault;
    }

    @Nonnull
    @Override
    protected String fieldsToString() {
        return super.fieldsToString() + ", default=" + getIsDefault();
    }

    protected abstract static class AbstractBranchBuilder<B extends AbstractBranchBuilder<B, R>, R extends Branch>
            extends AbstractRefBuilder<B, R> {

        private boolean isDefault;

        public AbstractBranchBuilder() {
        }

        public AbstractBranchBuilder(R ref) {
            super(ref);

            isDefault = ref.getIsDefault();
        }

        public B isDefault(boolean value) {
            isDefault = value;

            return self();
        }
    }

    public static class Builder extends AbstractBranchBuilder<Builder, Branch> {

        public Builder() {
        }

        public Builder(Branch ref) {
            super(ref);
        }

        @Nonnull
        @Override
        public SimpleBranch build() {
            return new SimpleBranch(this);
        }

        @Nonnull
        @Override
        protected Builder self() {
            return this;
        }
    }
}
