{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://capp.local/schemas/capp.showroom.product.v1.schema.json",
  "title": "cApp Showroom Product v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "protocol",
    "id",
    "app",
    "listing",
    "classification",
    "commercial",
    "demo",
    "repository"
  ],
  "properties": {
    "protocol": {
      "const": "capp.showroom.product.v1"
    },
    "id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160,
      "pattern": "^[a-z0-9._-]+$"
    },
    "app": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name"
      ],
      "properties": {
        "appId": {
          "type": "string",
          "maxLength": 240
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "version": {
          "type": "string",
          "maxLength": 120
        }
      }
    },
    "listing": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "title",
        "summary"
      ],
      "properties": {
        "title": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "tagline": {
          "type": "string",
          "maxLength": 160
        },
        "summary": {
          "type": "string",
          "maxLength": 420
        },
        "description": {
          "type": "string",
          "maxLength": 6000
        },
        "features": {
          "type": "array",
          "maxItems": 10,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 160
          }
        }
      }
    },
    "classification": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kind",
        "stage"
      ],
      "properties": {
        "kind": {
          "enum": [
            "app",
            "game",
            "tool",
            "platform",
            "website",
            "ai",
            "service",
            "sidecar",
            "other"
          ]
        },
        "stage": {
          "enum": [
            "concept",
            "alpha",
            "beta",
            "production",
            "mature"
          ]
        },
        "categories": {
          "type": "array",
          "maxItems": 12,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 60
          }
        },
        "tags": {
          "type": "array",
          "maxItems": 24,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 48
          }
        },
        "platforms": {
          "type": "array",
          "maxItems": 6,
          "uniqueItems": true,
          "items": {
            "enum": [
              "web",
              "windows",
              "macos",
              "linux",
              "android",
              "ios"
            ]
          }
        }
      }
    },
    "commercial": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "availability"
      ],
      "properties": {
        "availability": {
          "enum": [
            "showcase-only",
            "for-sale",
            "licensing",
            "partnership",
            "open-source",
            "service",
            "open-to-discussion",
            "free"
          ]
        },
        "priceLabel": {
          "type": "string",
          "maxLength": 100
        },
        "licenseLabel": {
          "type": "string",
          "maxLength": 120
        }
      }
    },
    "media": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "coverUrl": {
          "$ref": "#/$defs/rawGitHubUrl"
        },
        "coverAlt": {
          "type": "string",
          "maxLength": 180
        },
        "gallery": {
          "type": "array",
          "maxItems": 12,
          "items": {
            "$ref": "#/$defs/mediaItem"
          }
        }
      }
    },
    "seller": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "displayName": {
          "type": "string",
          "maxLength": 120
        },
        "githubUrl": {
          "$ref": "#/$defs/httpsUrl"
        },
        "websiteUrl": {
          "$ref": "#/$defs/httpsUrl"
        },
        "contactUrl": {
          "$ref": "#/$defs/httpsUrl"
        }
      },
      "description": "Deprecated compatibility alias for publisher. New documents should use publisher."
    },
    "demo": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "latestUrl": {
          "$ref": "#/$defs/rawGitHubUrl"
        },
        "descriptorUrl": {
          "$ref": "#/$defs/rawGitHubUrl"
        },
        "artifactUrl": {
          "$ref": "#/$defs/rawGitHubUrl"
        },
        "archiveSha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        }
      },
      "anyOf": [
        {
          "required": [
            "latestUrl"
          ]
        },
        {
          "required": [
            "descriptorUrl"
          ]
        }
      ]
    },
    "repository": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "fullName",
        "branch"
      ],
      "properties": {
        "fullName": {
          "type": "string",
          "pattern": "^[^/\\s]+/[^/\\s]+$",
          "maxLength": 240
        },
        "branch": {
          "type": "string",
          "minLength": 1,
          "maxLength": 240
        }
      }
    },
    "publishedAt": {
      "type": "string",
      "maxLength": 120
    },
    "updatedAt": {
      "type": "string",
      "maxLength": 120
    },
    "project": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "projectId",
        "name",
        "mode",
        "primaryComponentId",
        "componentCount",
        "productSurfaceCount",
        "diagnosticSurfaceCount",
        "components"
      ],
      "properties": {
        "projectId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160,
          "pattern": "^[A-Za-z0-9._-]+$"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "mode": {
          "enum": [
            "single-component",
            "multi-component"
          ]
        },
        "primaryComponentId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160,
          "pattern": "^[A-Za-z0-9._-]+$"
        },
        "componentCount": {
          "type": "integer",
          "minimum": 1,
          "maximum": 128
        },
        "productSurfaceCount": {
          "type": "integer",
          "minimum": 0,
          "maximum": 128
        },
        "diagnosticSurfaceCount": {
          "type": "integer",
          "minimum": 0,
          "maximum": 128
        },
        "components": {
          "type": "array",
          "minItems": 1,
          "maxItems": 128,
          "items": {
            "$ref": "#/$defs/showroomComponent"
          }
        }
      }
    },
    "publisher": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "displayName": {
          "type": "string",
          "maxLength": 120
        },
        "githubUrl": {
          "$ref": "#/$defs/httpsUrl"
        },
        "websiteUrl": {
          "$ref": "#/$defs/httpsUrl"
        },
        "contactUrl": {
          "$ref": "#/$defs/httpsUrl"
        }
      },
      "description": "Canonical public identity for the individual, studio, team or organisation publishing this listing."
    }
  },
  "$defs": {
    "httpsUrl": {
      "type": "string",
      "pattern": "^https://",
      "maxLength": 2000
    },
    "rawGitHubUrl": {
      "type": "string",
      "pattern": "^https://raw\\.githubusercontent\\.com/",
      "maxLength": 2000
    },
    "mediaItem": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "url"
      ],
      "properties": {
        "url": {
          "$ref": "#/$defs/rawGitHubUrl"
        },
        "alt": {
          "type": "string",
          "maxLength": 180
        }
      }
    },
    "showroomDemo": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "latestUrl": {
          "$ref": "#/$defs/rawGitHubUrl"
        },
        "descriptorUrl": {
          "$ref": "#/$defs/rawGitHubUrl"
        },
        "artifactUrl": {
          "$ref": "#/$defs/rawGitHubUrl"
        },
        "archiveSha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        }
      },
      "anyOf": [
        {
          "required": [
            "latestUrl"
          ]
        },
        {
          "required": [
            "descriptorUrl"
          ]
        }
      ]
    },
    "showroomComponent": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "appId",
        "name",
        "surfaceKind",
        "readiness",
        "demo"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160,
          "pattern": "^[A-Za-z0-9._-]+$"
        },
        "appId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 240
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "version": {
          "type": "string",
          "maxLength": 120
        },
        "surfaceKind": {
          "enum": [
            "product",
            "diagnostic"
          ]
        },
        "readiness": {
          "type": "string",
          "maxLength": 80
        },
        "summary": {
          "type": "string",
          "maxLength": 280
        },
        "demo": {
          "$ref": "#/$defs/showroomDemo"
        },
        "listing": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "title": {
              "type": "string",
              "maxLength": 120
            },
            "tagline": {
              "type": "string",
              "maxLength": 160
            },
            "summary": {
              "type": "string",
              "maxLength": 420
            },
            "description": {
              "type": "string",
              "maxLength": 3000
            },
            "features": {
              "type": "array",
              "maxItems": 8,
              "uniqueItems": true,
              "items": {
                "type": "string",
                "minLength": 1,
                "maxLength": 160
              }
            }
          }
        },
        "media": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "coverUrl": {
              "$ref": "#/$defs/rawGitHubUrl"
            },
            "coverAlt": {
              "type": "string",
              "maxLength": 180
            },
            "gallery": {
              "type": "array",
              "maxItems": 6,
              "items": {
                "$ref": "#/$defs/mediaItem"
              }
            }
          }
        }
      }
    }
  }
}
