{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://workspai.dev/contracts/workspace-archive-manifest.v1.json",
  "title": "Workspai Workspace Archive Manifest v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "version",
    "kind",
    "workspaceName",
    "exportedAt",
    "security",
    "files"
  ],
  "properties": {
    "schemaVersion": {
      "const": "workspai-workspace-archive-manifest-v1"
    },
    "version": {
      "const": 1
    },
    "kind": {
      "const": "workspai.workspace.archive"
    },
    "workspaceName": {
      "type": "string",
      "minLength": 1
    },
    "exportedAt": {
      "type": "string",
      "format": "date-time"
    },
    "exportedBy": {
      "enum": [
        "workspai",
        "workspai-vscode"
      ]
    },
    "archiveFormat": {
      "enum": [
        "zip-store",
        "zip-deflate"
      ]
    },
    "containerFormat": {
      "enum": [
        "zip",
        "zip64"
      ]
    },
    "compression": {
      "enum": [
        "store",
        "deflate"
      ]
    },
    "streaming": {
      "type": "boolean"
    },
    "security": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "envFilesIncluded",
        "excludedByDefault"
      ],
      "properties": {
        "envFilesIncluded": {
          "type": "boolean"
        },
        "excludedByDefault": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        }
      }
    },
    "externalProjects": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "relationship",
          "included",
          "requiredAction"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1
          },
          "relationship": {
            "enum": [
              "adopted",
              "linked",
              "imported",
              "managed",
              "restored"
            ]
          },
          "included": {
            "const": false
          },
          "requiredAction": {
            "const": "relink"
          }
        }
      }
    },
    "portableContract": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schemaVersion",
        "kind",
        "generatedAt",
        "workspace",
        "projects"
      ],
      "properties": {
        "schemaVersion": {
          "const": 1
        },
        "kind": {
          "const": "rapidkit.workspace.contract"
        },
        "generatedAt": {
          "type": "string",
          "format": "date-time"
        },
        "workspace": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "name"
          ],
          "properties": {
            "name": {
              "type": "string",
              "minLength": 1
            },
            "profile": {
              "type": "string",
              "minLength": 1
            }
          }
        },
        "projects": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "slug",
              "relativePath",
              "modules",
              "ports",
              "contracts"
            ],
            "properties": {
              "slug": {
                "type": "string",
                "minLength": 1
              },
              "relativePath": {
                "type": "string",
                "minLength": 1,
                "not": {
                  "pattern": "^external/"
                }
              },
              "source": {
                "enum": [
                  "workspace",
                  "local-folder",
                  "git-url",
                  "adopted-local"
                ]
              },
              "relationship": {
                "enum": [
                  "imported",
                  "adopted"
                ]
              },
              "runtime": {
                "type": "string",
                "minLength": 1
              },
              "framework": {
                "type": "string",
                "minLength": 1
              },
              "kit": {
                "type": "string",
                "minLength": 1
              },
              "modules": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "uniqueItems": true
              },
              "ports": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "name",
                    "port",
                    "protocol"
                  ],
                  "properties": {
                    "name": {
                      "type": "string",
                      "minLength": 1
                    },
                    "port": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 65535
                    },
                    "protocol": {
                      "enum": [
                        "http",
                        "https",
                        "grpc",
                        "tcp",
                        "udp"
                      ]
                    }
                  }
                }
              },
              "contracts": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "owns",
                  "apis",
                  "publishes",
                  "consumes",
                  "dependsOn",
                  "env"
                ],
                "properties": {
                  "owns": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "uniqueItems": true
                  },
                  "apis": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "name",
                        "basePath"
                      ],
                      "properties": {
                        "name": {
                          "type": "string",
                          "minLength": 1
                        },
                        "basePath": {
                          "type": "string",
                          "minLength": 1
                        }
                      }
                    }
                  },
                  "publishes": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "uniqueItems": true
                  },
                  "consumes": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "uniqueItems": true
                  },
                  "dependsOn": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "uniqueItems": true
                  },
                  "env": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "uniqueItems": true
                  }
                }
              }
            }
          }
        }
      }
    },
    "files": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "path",
          "size",
          "sha256"
        ],
        "properties": {
          "path": {
            "type": "string",
            "minLength": 1
          },
          "size": {
            "type": "integer",
            "minimum": 0
          },
          "sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          }
        }
      }
    }
  }
}
