# Type contracts for CI/CD-triggered pipelines
#
# A CiCdPipeline binds a named CI/CD event to an ordered list of steps.
# `pipeline_type` must be "ci_cd".
#
# At runtime, ci_cd pipelines are dispatched via a dedicated HTTP endpoint
# (not a NATS subscription).  The `event` field is the path token used
# in the webhook URL: POST /pipeline/trigger/{event}.
#
# Validate:
#   nickel export --format json --import-path site/nickel site/config/pipelines.ncl

let C = import "pipelines/contracts.ncl" in

let OneOf = fun allowed =>
  std.contract.from_predicate (fun v => std.array.elem v allowed)
in

let NonEmpty = std.contract.from_predicate (fun s =>
  std.is_string s && std.string.length s > 0)
in

{
  CiCdPipeline = {
    pipeline_type | OneOf ["ci_cd"]
      | doc "Discriminator — must be \"ci_cd\" for this contract.",

    name | String | NonEmpty
      | doc "Human-readable identifier used in log output.",

    event | String | NonEmpty
      | doc "CI/CD event name used in the webhook trigger path.
             Example: 'deploy.completed', 'test.passed'.",

    steps | Array C.PipelineStep
      | doc "Ordered actions executed sequentially on each trigger."
      | default = [],
  },

  CiCdPipelinesFile = {
    pipelines | Array CiCdPipeline
      | doc "List of CI/CD-triggered pipelines defined in this file."
      | default = [],
  },
}
