{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://pamphp.com/schemas/pam.schema.json",
  "title": "PAM project",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "type",
    "name"
  ],
  "properties": {
    "$schema": {
      "type": "string"
    },
    "schema": {
      "const": 1
    },
    "type": {
      "type": "integer",
      "minimum": 1,
      "maximum": 6,
      "description": "1 API, 2 Native, 3 Laravel, 4 Desktop, 5 Raw runtime, 6 Product workspace"
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 80
    },
    "version": {
      "type": "string",
      "maxLength": 64,
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+(?:-[0-9A-Za-z.-]+)?$"
    },
    "native": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "applicationId",
        "starter",
        "platforms"
      ],
      "properties": {
        "applicationId": {
          "type": "string",
          "minLength": 3,
          "maxLength": 255,
          "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)+$"
        },
        "starter": {
          "type": "integer",
          "minimum": 1,
          "maximum": 6,
          "description": "1 Blank, 2 Tabs, 3 Authentication, 4 E-commerce, 5 Chat, 6 Showcase"
        },
        "platforms": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "integer",
            "minimum": 1,
            "maximum": 3,
            "description": "1 Android, 2 iOS, 3 Android TV"
          }
        }
      }
    },
    "workspace": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "surfaceCodes",
        "contractPath"
      ],
      "properties": {
        "surfaceCodes": {
          "type": "array",
          "minItems": 3,
          "maxItems": 3,
          "uniqueItems": true,
          "prefixItems": [
            {
              "const": 1,
              "description": "Server"
            },
            {
              "const": 2,
              "description": "Native"
            },
            {
              "const": 3,
              "description": "Desktop"
            }
          ],
          "items": false
        },
        "contractPath": {
          "const": "packages/contracts"
        }
      }
    },
    "deploy": {
      "type": "object",
      "description": "Defaults of `pam deploy:remote`; command-line options win.",
      "additionalProperties": false,
      "properties": {
        "host": {
          "type": "string",
          "pattern": "^[A-Za-z0-9@._\\[\\]:][A-Za-z0-9@._\\[\\]:-]{0,254}$"
        },
        "path": {
          "type": "string",
          "pattern": "^[A-Za-z0-9/._+@][A-Za-z0-9/._+@-]{0,511}$",
          "description": "Absolute, or relative to the remote home; defaults to pam-apps/<name>."
        },
        "name": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$"
        },
        "workers": {
          "type": "integer",
          "minimum": 1,
          "maximum": 65535
        },
        "healthCheckUrl": {
          "type": "string",
          "pattern": "^http://"
        },
        "keep": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100,
          "description": "Releases kept on the server (default 5)."
        },
        "pam": {
          "type": "string",
          "minLength": 1,
          "description": "The pam executable on the server (default pam)."
        }
      }
    },
    "commands": {
      "type": "object",
      "propertyNames": {
        "pattern": "^[a-z0-9][a-z0-9:_-]{0,95}$"
      },
      "additionalProperties": {
        "oneOf": [
          {
            "type": "string",
            "minLength": 1
          },
          {
            "type": "object",
            "additionalProperties": false,
            "oneOf": [
              {
                "required": [
                  "script"
                ]
              },
              {
                "required": [
                  "bin"
                ]
              }
            ],
            "properties": {
              "script": {
                "type": "string",
                "minLength": 1
              },
              "bin": {
                "type": "string",
                "minLength": 1
              },
              "arguments": {
                "type": "array",
                "maxItems": 32,
                "items": {
                  "type": "string",
                  "maxLength": 4096
                }
              },
              "description": {
                "type": "string",
                "maxLength": 240
              }
            }
          }
        ]
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "type": {
            "const": 6
          }
        },
        "required": [
          "type"
        ]
      },
      "then": {
        "required": [
          "workspace"
        ]
      }
    }
  ]
}
