001package gudusoft.gsqlparser.lineage2.contract;
002
003import java.util.ArrayList;
004import java.util.Collections;
005import java.util.List;
006
007/**
008 * Contract {@code Statement} entry (lineage2-contract.md ยง2.1).
009 * {@code statementIndex} is 1-based, ordered by source position within the
010 * unit. {@code kind} is the contract statement-kind string (e.g.
011 * {@code "SELECT"}, {@code "SELECT_INTO"}, {@code "UNKNOWN"} for
012 * statements the parser could not type).
013 *
014 * <p>Internal API: not part of the public gsqlparser surface.
015 */
016public final class ContractStatement {
017
018    private final int statementIndex;
019    private final String kind;
020    private final String queryFingerprint;
021    private final SourceLocation sourceLocation;
022    private final List<ContractDiagnostic> diagnostics;
023
024    public ContractStatement(int statementIndex, String kind,
025                             String queryFingerprint,
026                             SourceLocation sourceLocation,
027                             List<ContractDiagnostic> diagnostics) {
028        if (kind == null || queryFingerprint == null) {
029            throw new IllegalArgumentException(
030                    "kind and queryFingerprint must not be null");
031        }
032        this.statementIndex = statementIndex;
033        this.kind = kind;
034        this.queryFingerprint = queryFingerprint;
035        this.sourceLocation = sourceLocation;
036        this.diagnostics = (diagnostics == null)
037                ? Collections.<ContractDiagnostic>emptyList()
038                : Collections.unmodifiableList(new ArrayList<>(diagnostics));
039    }
040
041    public int getStatementIndex() {
042        return statementIndex;
043    }
044
045    public String getKind() {
046        return kind;
047    }
048
049    public String getQueryFingerprint() {
050        return queryFingerprint;
051    }
052
053    /** Nullable. */
054    public SourceLocation getSourceLocation() {
055        return sourceLocation;
056    }
057
058    /** Never null; possibly empty (the JSON key is omitted when empty). */
059    public List<ContractDiagnostic> getDiagnostics() {
060        return diagnostics;
061    }
062}