{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Service manifest",
  "type": "object",
  "additionalProperties": false,

  "properties": {
    "uid": {
      "type": "string",
      "pattern": "^[a-z_-]+$",
      "description": "String (regex: a-z_-)\nУникальный идентификатор сервиса.",
      "$comment": "Если в приложении уже установлен такой uid, то как в android - уведомляем пользователя что ранее установленная схема не доверяет данному источнику."
    },
    "version": {
      "type": "string",
      "description": "String\nService API version"
    },
    "schemaSources": {
      "description": "Array<String>\nДомены с которых разрешено скачивать новую версию репозитория",
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "i18n": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "required": ["en"],
        "properties": {
          "en": { "type": "string" }
        },
        "additionalProperties": { "type": "string" }
      },
      "description": "Object<{ [tid]: { en: String; [langCode]: String } }>\nСловарь локализации\n\nНапример: { serviceName: { en: \"Some great service\"}}\nИспользование в схеме: \"name\": \"tid\" или \"name\": { \"t\": \"tid\", \"params\": { ... }}, т.е.: \"name\": \"serviceName\" или \"name\": { \"t\": \"something\", \"params\": { \"count\": 2 }}"
    },
    "methods": {
      "type": "object",
      "required": ["GetAccounts"],
      "additionalProperties": {
        "$ref": "#/definitions/Method"
      }
    },
    "auth": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["name", "initialStep", "steps"],
        "properties": {
          "name": { "$ref": "#/definitions/i18n" },
          "initialStep": { "type": "string" },
          "steps": {
            "type": "object",
            "additionalProperties": {
              "type": "object",
              "properties": {
                "ui": {
                  "type": "object",
                  "additionalProperties": {
                    "$ref": "#/definitions/UIinput"
                  }
                },
                "pipeline": {
                  "type": "array",
                  "items": { "$ref": "#/definitions/Action" }
                }
              }
            }
          }
        }
      }
    }
  },
  "required": ["uid", "version", "methods"],

  "definitions": {
    "UIinput": {
      "type": "object",
      "required": ["type"],
      "properties": {
        "type": {
          "type": "string",
          "enum": ["phone", "password"]
        },
        "label": {
          "$ref": "#/definitions/i18n"
        },
        "placeholder": {
          "$ref": "#/definitions/i18n"
        }
      }
    },
    "i18n": {
      "anyOf": [
        {
          "type": "string",
          "description": "Обычный текст (хардкод)"
        },
        {
          "type": "object",
          "description": "Строка из локализации",
          "required": ["t"],
          "properties": {
            "t": {
              "type": "string",
              "description": "Ключ перевода (tid)"
            },
            "params": {
              "type": "object",
              "description": "Динамические параметры (например, count)",
              "additionalProperties": {
                "type": ["string", "number", "boolean"]
              }
            }
          },
          "additionalProperties": false
        }
      ]
    },
    "Method": {
      "type": "object",
      "properties": {
        "pipeline": {
          "type": "array",
          "items": { "$ref": "#/definitions/Action" }
        }
      },
      "required": ["pipeline"],
      "additionalProperties": false
    },
    "Header": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      }
    },
    "Action": {
      "description": "Действие/Шаг",
      "oneOf": [
        {
          "title": "ActionNetworkFetchGet",
          "type": "object",
          "required": ["use", "url"],
          "properties": {
            "use": { "const": "network.fetch.get" },
            "set": { "type": "string" },
            "url": { "type": "string" },
            "headers": {
              "type": "array",
              "items": { "$ref": "#/definitions/Header" }
            }
          }
        },
        {
          "title": "ActionNetworkFetchDelete",
          "type": "object",
          "required": ["use", "url"],
          "properties": {
            "use": { "const": "network.fetch.delete" },
            "set": { "type": "string" },
            "url": { "type": "string" }
          }
        },
        {
          "title": "ActionNetworkFetchPost",
          "type": "object",
          "required": ["use", "url"],
          "properties": {
            "use": { "const": "network.fetch.post" },
            "set": { "type": "string" },
            "url": { "type": "string" },
            "body": { "type": ["object", "string", "array"] }
          }
        },
        {
          "title": "ActionNetworkFetchPut",
          "type": "object",
          "required": ["use", "url"],
          "properties": {
            "use": { "const": "network.fetch.put" },
            "set": { "type": "string" },
            "url": { "type": "string" },
            "body": { "type": ["object", "string", "array"] }
          }
        },
        {
          "title": "ActionNetworkFetchPatch",
          "type": "object",
          "required": ["use", "url"],
          "properties": {
            "use": { "const": "network.fetch.patch" },
            "set": { "type": "string" },
            "url": { "type": "string" },
            "body": { "type": ["object", "string", "array"] }
          }
        },
        {
          "title": "ActionDebug",
          "type": "object",
          "required": ["use"],
          "properties": {
            "use": { "const": "debug" },
            "set": { "type": "string" },
            "tag": { "type": "string" }
          },
          "additionalProperties": false
        }
      ]
    }
  }
}
