package com.atlassian.bitbucket.mesh.repository;

import javax.annotation.Nonnull;
import java.time.Instant;
import java.util.Objects;

import static java.util.Objects.requireNonNull;

public class WorkTreeState {

    private final Instant expiry;
    private final boolean hasAlternates;
    private final long id;
    private final String repositoryId;

    private WorkTreeState(Builder builder) {
        expiry = requireNonNull(builder.expiry, "expiry");
        hasAlternates = builder.hasAlternates;
        repositoryId = requireNonNull(builder.repositoryId, "repositoryId");
        id = builder.id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        WorkTreeState that = (WorkTreeState) o;
        return id == that.id;
    }

    @Nonnull
    public Instant getExpiry() {
        return expiry;
    }

    public long getId() {
        return id;
    }

    @Nonnull
    public String getRepositoryId() {
        return repositoryId;
    }

    public boolean hasAlternates() {
        return hasAlternates;
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

    public static class Builder {

        private boolean hasAlternates;
        private Instant expiry;
        private String repositoryId;
        private long id;

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

        @Nonnull
        public Builder expiry(@Nonnull Instant value) {
            expiry = requireNonNull(value, "expiry");

            return this;
        }

        @Nonnull
        public Builder hasAlternates(boolean value) {
            hasAlternates = value;

            return this;
        }

        @Nonnull
        public Builder id(long value) {
            id = value;

            return this;
        }

        @Nonnull
        public Builder repositoryId(@Nonnull String value) {
            repositoryId = requireNonNull(value, "repositoryId");

            return this;
        }
    }
}
