{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/alpibrusl/cancho-tools/schemas/list.v1.json",
  "title": "list.v1",
  "description": "One line of an NDJSON stream. The last line of a stream that finished is the end record; a stream without one was cut short.",
  "oneOf": [
    {
      "$ref": "#/$defs/entry"
    },
    {
      "$ref": "#/$defs/error_record"
    },
    {
      "$ref": "#/$defs/end"
    }
  ],
  "$defs": {
    "text_or_bytes": {
      "description": "UTF-8 text as a string; other bytes as base64 (RFC 4648 section 4, padded).",
      "oneOf": [
        {
          "type": "string"
        },
        {
          "type": "object",
          "properties": {
            "b64": {
              "type": "string",
              "pattern": "^[A-Za-z0-9+/]*={0,2}$"
            }
          },
          "required": [
            "b64"
          ],
          "additionalProperties": false
        }
      ]
    },
    "repair": {
      "oneOf": [
        {
          "type": "null"
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "retry"
            },
            "argv": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "minItems": 1
            }
          },
          "required": [
            "kind",
            "argv"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "none"
            },
            "reason": {
              "type": "string"
            }
          },
          "required": [
            "kind",
            "reason"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "choose"
            },
            "options": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "argv": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                },
                "required": [
                  "argv"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "kind",
            "options"
          ],
          "additionalProperties": false
        }
      ]
    },
    "error": {
      "type": "object",
      "properties": {
        "code": {
          "enum": [
            "GENERAL_ERROR",
            "INVALID_ARGS",
            "NOT_FOUND",
            "PERMISSION_DENIED",
            "CONFLICT",
            "PRECONDITION_FAILED"
          ]
        },
        "rule": {
          "type": "string",
          "pattern": "^[a-z]+\\.[a-z0-9-]+$"
        },
        "message": {
          "type": "string"
        },
        "hint": {
          "type": [
            "string",
            "null"
          ]
        },
        "repair": {
          "$ref": "#/$defs/repair"
        },
        "detail": {
          "type": "object"
        }
      },
      "required": [
        "code",
        "rule",
        "message",
        "hint",
        "repair",
        "detail"
      ],
      "additionalProperties": false
    },
    "meta": {
      "type": "object",
      "properties": {
        "version": {
          "type": "string"
        }
      },
      "required": [
        "version"
      ],
      "additionalProperties": false
    },
    "end": {
      "type": "object",
      "properties": {
        "type": {
          "const": "end"
        },
        "ok": {
          "type": "boolean"
        },
        "command": {
          "const": "list"
        },
        "schema": {
          "const": "list.v1"
        },
        "complete": {
          "type": "boolean"
        },
        "entries": {
          "type": "integer",
          "minimum": 0
        },
        "errors": {
          "type": "integer",
          "minimum": 0
        },
        "truncated": {
          "type": "boolean"
        },
        "next": {
          "oneOf": [
            {
              "type": "null"
            },
            {
              "type": "object",
              "properties": {
                "skip": {
                  "type": "integer",
                  "minimum": 0
                }
              },
              "required": [
                "skip"
              ],
              "additionalProperties": false
            }
          ]
        }
      },
      "required": [
        "type",
        "ok",
        "command",
        "schema",
        "complete",
        "entries",
        "errors",
        "truncated",
        "next"
      ],
      "additionalProperties": false
    },
    "error_record": {
      "type": "object",
      "properties": {
        "type": {
          "const": "error"
        },
        "error": {
          "$ref": "#/$defs/error"
        }
      },
      "required": [
        "type",
        "error"
      ],
      "additionalProperties": false
    },
    "entry": {
      "type": "object",
      "properties": {
        "type": {
          "const": "entry"
        },
        "path": {
          "$ref": "#/$defs/text_or_bytes"
        },
        "kind": {
          "enum": [
            "file",
            "directory",
            "link",
            "other",
            "unknown"
          ]
        },
        "depth": {
          "type": "integer",
          "minimum": 1
        },
        "size": {
          "type": "integer",
          "minimum": 0
        },
        "mtime": {
          "type": "integer"
        }
      },
      "required": [
        "type",
        "path",
        "kind",
        "depth"
      ],
      "additionalProperties": false
    }
  }
}
