package com.atlassian.bitbucket.mesh.repository;

import com.atlassian.bitbucket.mesh.rpc.v1.RpcRepositorySize;

import javax.annotation.Nonnull;

public class RepositorySize {

    private final long garbageSize;
    private final long inPackSize;
    private final long looseSize;

    private RepositorySize(Builder builder) {
        garbageSize = builder.garbageSize;
        inPackSize = builder.inPackSize;
        looseSize = builder.looseSize;
    }

    public long getGarbageSize() {
        return garbageSize;
    }

    public long getInPackSize() {
        return inPackSize;
    }

    public long getLooseSize() {
        return looseSize;
    }

    @Nonnull
    public RpcRepositorySize toRepositorySize() {
        return RpcRepositorySize.newBuilder()
                .setGarbageSize(getGarbageSize())
                .setInPackSize(getInPackSize())
                .setLooseSize(getLooseSize())
                .build();
    }

    public static class Builder {

        private long garbageSize;
        private long inPackSize;
        private long looseSize;

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

        /**
         * @param value the disk space consumed by garbage files, in KiB
         * @return the builder
         */
        @Nonnull
        public Builder garbageSize(long value) {
            garbageSize = value;
            return this;
        }

        /**
         * @param value the disk space consumed by the packs, in KiB
         * @return the builder
         */
        @Nonnull
        public Builder inPackSize(long value) {
            inPackSize = value;
            return this;
        }

        /**
         * @param value the disk space consumed by loose objects, in KiB
         * @return the builder
         */
        @Nonnull
        public Builder looseSize(long value) {
            looseSize = value;
            return this;
        }
    }

}
