001package gudusoft.gsqlparser.catalog.input.model;
002
003import java.util.Objects;
004
005/**
006 * Sequence entry inside a {@link SchemaModel}.
007 *
008 * <p>Plan ยง6. {@code startsWith} and {@code incrementBy} are nullable to model
009 * adapters that do not surface those values (e.g., minimal JDBC metadata).</p>
010 */
011public final class SequenceModel {
012
013    private final String name;
014    private final Long startsWith;
015    private final Long incrementBy;
016
017    private SequenceModel(Builder b) {
018        if (b.name == null || b.name.isEmpty()) {
019            throw new IllegalArgumentException("SequenceModel.name is required");
020        }
021        if (b.incrementBy != null && b.incrementBy == 0L) {
022            throw new IllegalArgumentException(
023                "SequenceModel.incrementBy must not be zero (sequence '" + b.name + "')");
024        }
025        this.name = b.name;
026        this.startsWith = b.startsWith;
027        this.incrementBy = b.incrementBy;
028    }
029
030    public static Builder builder() {
031        return new Builder();
032    }
033
034    public String name() {
035        return name;
036    }
037
038    public Long startsWith() {
039        return startsWith;
040    }
041
042    public Long incrementBy() {
043        return incrementBy;
044    }
045
046    @Override
047    public boolean equals(Object o) {
048        if (this == o) return true;
049        if (!(o instanceof SequenceModel)) return false;
050        SequenceModel that = (SequenceModel) o;
051        return name.equals(that.name)
052            && Objects.equals(startsWith, that.startsWith)
053            && Objects.equals(incrementBy, that.incrementBy);
054    }
055
056    @Override
057    public int hashCode() {
058        return Objects.hash(name, startsWith, incrementBy);
059    }
060
061    @Override
062    public String toString() {
063        return "SequenceModel{name=" + name
064            + ", startsWith=" + startsWith
065            + ", incrementBy=" + incrementBy + '}';
066    }
067
068    public static final class Builder {
069
070        private String name;
071        private Long startsWith;
072        private Long incrementBy;
073
074        private Builder() {
075        }
076
077        public Builder name(String v) {
078            this.name = v;
079            return this;
080        }
081
082        public Builder startsWith(Long v) {
083            this.startsWith = v;
084            return this;
085        }
086
087        public Builder incrementBy(Long v) {
088            this.incrementBy = v;
089            return this;
090        }
091
092        public SequenceModel build() {
093            return new SequenceModel(this);
094        }
095    }
096}