/**
 * Single source of truth for issue-code categories shared between the check
 * engine (core/check.ts — summary tallies) and the check command renderer
 * (cli/check.ts — error grouping). Keeping one definition means the count in the
 * summary line and the rendered "Structural" group can never drift apart, which
 * is exactly what happened when each file hard-coded its own set.
 */

/**
 * Structural validation codes — graph-shape and config errors that always block
 * `yg check` regardless of verification state. Both the summary tally and the
 * rendered grouping read this one set.
 */
export const STRUCTURAL_CODES = new Set<string>([
  'yaml-invalid',
  'type-invalid',
  'relation-broken',
  'flow-node-broken',
  'aspect-undefined',
  'overlapping-mapping',
  'file-duplicate-mapping',
  'structural-cycle',
  'config-invalid',
  'duplicate-aspect-id',
  'node-yaml-missing',
  'implied-aspect-missing',
  'aspect-implies-cycle',
  'event-unpaired',
  'schema-missing',
  'type-without-when-with-mapping',
  'type-when-mismatch',
  'file-mapping-gitignored',
  // A git-tracked file is matched by a directory/glob mapping entry (so the
  // coverage scan counts it covered) but is gitignored — the hash layer drops it
  // from the node's subject set, so no reviewer ever sees it (a false green).
  // Blocking, distinct from the plain "not covered" coverage error.
  'mapped-file-gitignored',
  'enforce-strict-without-when',
  'architecture-cycle',
  'when-predicate-invalid',
  'when-unknown-type',
  'when-unknown-node',
  'when-unknown-port',
  // Port-contract codes — blocking architecture-gate errors (documented in the
  // ports-and-relations knowledge topic); belong in the single-source structural set.
  'port-missing-consumes',
  'port-undefined',
  'port-missing-aspect',
  'consumes-without-ports',
  'relation-target-forbidden',
  'aspect-unexpected-rule-source',
  'aspect-missing-rule-source',
  'aspect-empty',
  'file-unreadable',
  'aspect-references-on-deterministic',
  'aspect-scope-invalid',
  'aspect-scope-on-aggregate',
  'aspect-references-on-aggregate',
  'aspect-reference-broken',
  'aspect-reference-invalid-form',
  'aspect-reference-blank-path',
  'aspect-reference-escape',
  'aspect-reference-duplicate',
  'aspect-tier-unknown',
  'mapping-escapes-repo',
  // The lock file is unparseable, garbled, conflict-markered, or an unknown
  // version. Fail closed — blocking, structural, independent of any pair state.
  'lock-invalid',
  // yg-secrets.yaml carries a non-credential field (only api_key is allowed).
  // Emitted as a blocking error and gates --approve; structural so the summary
  // tally counts it and computeSuggestedNext can point at it.
  'secrets-non-credential-field',
]);

/**
 * Metadata-completeness codes surfaced in the summary. NOTE: despite the
 * historical "non-blocking" framing, `description-missing` is emitted at
 * `severity: 'error'` (see checkMissingDescriptions) and therefore BLOCKS
 * `yg check`. Membership here governs grouping/tally only, not severity —
 * the emitting check decides whether a code blocks.
 */
export const COMPLETENESS_CODES = new Set<string>(['description-missing']);

/**
 * Gating codes — a structural validation failure that makes reviewer/tier
 * resolution impossible. When any of these is present, the `--approve` fill
 * stage ABORTS before dispatching any verification (no fills, no LLM calls):
 * the graph is broken in a way that would make every verdict meaningless.
 *
 * Shared gating-code set consumed by the fill stage (core/fill.ts).
 */
export const APPROVE_GATING_CODES = new Set<string>([
  'config-reviewer-missing',
  'config-tiers-missing',
  'config-tiers-empty',
  'config-default-tier-missing',
  'config-default-tier-unknown',
  'config-tier-provider-missing',
  'config-tier-provider-unknown',
  'config-tier-config-missing',
  'config-tier-config-not-mapping',
  'config-tier-consensus-invalid',
  'config-tier-name-invalid',
  'config-tier-name-reserved',
  'config-reviewer-unknown-key',
  'config-tier-unknown-key',
  'aspect-reviewer-missing',
  'aspect-reviewer-not-mapping',
  'aspect-reviewer-type-missing',
  'aspect-reviewer-type-invalid',
  'aspect-reviewer-unknown-key',
  'aspect-tier-on-deterministic',
  'aspect-tier-unknown',
  'secrets-non-credential-field',
]);
