{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://rsasaki0109.github.io/lidar_slam_ros2/schemas/package-manager-release-readiness-v1.schema.json",
  "title": "Public package-manager release readiness report v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "schema_uri",
    "status",
    "candidate",
    "source_ref",
    "remote",
    "selected_run",
    "checks",
    "actions"
  ],
  "properties": {
    "schema_version": {"const": 1},
    "schema_uri": {
      "const": "https://rsasaki0109.github.io/lidar_slam_ros2/schemas/package-manager-release-readiness-v1.schema.json"
    },
    "status": {
      "enum": [
        "SOURCE_REF_MISSING",
        "NOT_RUN",
        "RUNNING",
        "FAILED",
        "READY",
        "BLOCKED"
      ]
    },
    "candidate": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "product_version",
        "source_ref",
        "apt_channel",
        "mode",
        "run_name"
      ],
      "properties": {
        "product_version": {
          "type": "string",
          "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
        },
        "source_ref": {"type": "string", "pattern": "^v[0-9]+\\.[0-9]+\\.[0-9]+$"},
        "apt_channel": {"const": "main"},
        "mode": {"const": "clean-install"},
        "run_name": {"type": "string", "minLength": 1}
      }
    },
    "source_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": ["ref", "resolved", "commit_sha"],
      "properties": {
        "ref": {"type": "string", "pattern": "^v[0-9]+\\.[0-9]+\\.[0-9]+$"},
        "resolved": {"type": "boolean"},
        "commit_sha": {
          "oneOf": [
            {"type": "null"},
            {"type": "string", "pattern": "^[a-f0-9]{40}$"}
          ]
        }
      },
      "allOf": [
        {
          "if": {"properties": {"resolved": {"const": true}}},
          "then": {"properties": {"commit_sha": {"type": "string"}}},
          "else": {"properties": {"commit_sha": {"type": "null"}}}
        }
      ]
    },
    "remote": {
      "type": "object",
      "additionalProperties": false,
      "required": ["inspected", "errors", "matching_runs"],
      "properties": {
        "inspected": {"type": "boolean"},
        "errors": {
          "type": "array",
          "items": {"type": "string", "minLength": 1}
        },
        "matching_runs": {"type": "integer", "minimum": 0}
      }
    },
    "selected_run": {
      "oneOf": [
        {"type": "null"},
        {"$ref": "#/definitions/run"}
      ]
    },
    "checks": {
      "type": "array",
      "uniqueItems": true,
      "items": {"$ref": "#/definitions/check"}
    },
    "actions": {
      "type": "array",
      "uniqueItems": true,
      "items": {"type": "string", "minLength": 1}
    }
  },
  "definitions": {
    "check": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "status", "detail"],
      "properties": {
        "id": {"type": "string", "minLength": 1},
        "status": {"enum": ["PASS", "FAIL"]},
        "detail": {"type": "string", "minLength": 1}
      }
    },
    "job": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "status", "conclusion"],
      "properties": {
        "name": {"type": ["string", "null"]},
        "status": {"type": ["string", "null"]},
        "conclusion": {"type": ["string", "null"]}
      }
    },
    "run": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "html_url",
        "display_title",
        "event",
        "status",
        "conclusion",
        "workflow_path",
        "head_sha",
        "jobs"
      ],
      "properties": {
        "id": {"type": ["integer", "null"]},
        "html_url": {"type": ["string", "null"]},
        "display_title": {"type": ["string", "null"]},
        "event": {"type": ["string", "null"]},
        "status": {"type": ["string", "null"]},
        "conclusion": {"type": ["string", "null"]},
        "workflow_path": {"type": ["string", "null"]},
        "head_sha": {"type": ["string", "null"]},
        "jobs": {
          "type": "array",
          "items": {"$ref": "#/definitions/job"}
        }
      }
    }
  },
  "allOf": [
    {
      "if": {"properties": {"status": {"const": "READY"}}},
      "then": {
        "properties": {
          "source_ref": {
            "properties": {"resolved": {"const": true}}
          },
          "remote": {
            "properties": {
              "inspected": {"const": true},
              "errors": {"maxItems": 0}
            }
          },
          "selected_run": {"type": "object"},
          "checks": {
            "minItems": 7,
            "items": {
              "properties": {"status": {"const": "PASS"}}
            }
          },
          "actions": {"maxItems": 0}
        }
      }
    },
    {
      "if": {"properties": {"status": {"const": "SOURCE_REF_MISSING"}}},
      "then": {
        "properties": {
          "source_ref": {
            "properties": {
              "resolved": {"const": false},
              "commit_sha": {"type": "null"}
            }
          },
          "selected_run": {"type": "null"},
          "actions": {"minItems": 1}
        }
      }
    }
  ]
}
