001package gudusoft.gsqlparser.slpc.model;
002
003import java.util.Collections;
004import java.util.List;
005
006/** Immutable root of a Static Lineage Projection Contract document. */
007public final class SlpcDocument {
008
009    public static final String CONTRACT_VERSION = "0.2.0";
010    public static final String IDENTITY_SPEC_VERSION = "SLPC-ID-V1";
011
012    private final SlpcObject root;
013
014    public SlpcDocument(SlpcObject root) {
015        if (root == null) {
016            throw new IllegalArgumentException("SLPC document root must not be null");
017        }
018        this.root = root;
019    }
020
021    public SlpcObject root() {
022        return root;
023    }
024
025    public String contractVersion() {
026        return root.string("contractVersion");
027    }
028
029    public String identitySpecVersion() {
030        return root.string("identitySpecVersion");
031    }
032
033    public SlpcObject producer() {
034        return root.object("producer");
035    }
036
037    public SlpcObject analysisContext() {
038        return root.object("analysisContext");
039    }
040
041    public List<Object> records(String collection) {
042        List<Object> records = root.array(collection);
043        return records == null ? Collections.<Object>emptyList() : records;
044    }
045
046    public static SlpcObject.Builder rootBuilder() {
047        return SlpcObject.builder()
048                .put("contractVersion", CONTRACT_VERSION)
049                .put("identitySpecVersion", IDENTITY_SPEC_VERSION);
050    }
051
052    @Override
053    public boolean equals(Object other) {
054        return other instanceof SlpcDocument && root.equals(((SlpcDocument) other).root);
055    }
056
057    @Override
058    public int hashCode() {
059        return root.hashCode();
060    }
061}