{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://modpacks.ch/schemas/project-link-v1.json",
  "title": "Modpacks.ch project link configuration",
  "description": "Repository-controlled project identities, verified destinations and creator support links.",
  "type": "object",
  "additionalProperties": false,
  "required": ["$schema", "version", "projects"],
  "properties": {
    "$schema": {
      "const": "https://modpacks.ch/schemas/project-link-v1.json"
    },
    "version": {
      "const": 1
    },
    "projects": {
      "type": "object",
      "additionalProperties": false,
      "minProperties": 1,
      "properties": {
        "curseforge": {
          "type": "string",
          "pattern": "^[1-9][0-9]{0,11}$"
        },
        "modrinth": {
          "type": "string",
          "pattern": "^[A-Za-z0-9]{3,64}$"
        },
        "github": {
          "type": "string",
          "pattern": "^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?/[A-Za-z0-9._-]{1,100}$",
          "description": "The verified repository identity as owner/repository. This lets dependency edges resolve a GitHub-only project to its release manifests."
        },
        "vintageStory": {
          "type": "string",
          "pattern": "^[1-9][0-9]{0,11}$"
        }
      }
    },
    "preferredDownload": {
      "enum": ["curseforge", "modrinth", "github"],
      "description": "The creator's preferred exact release destination. Verified app actions take precedence over the matching web file page; unavailable destinations fall back safely."
    },
    "destinations": {
      "type": "array",
      "maxItems": 10,
      "items": {
        "oneOf": [
          {
            "type": "object",
            "additionalProperties": false,
            "required": ["platform", "releases"],
            "properties": {
              "platform": {
                "const": "github"
              },
              "releases": {
                "const": true
              },
              "manifestAsset": {
                "type": "string",
                "default": "modpacksch-release.json",
                "pattern": "^[A-Za-z0-9._-]{1,80}\\.json$"
              }
            }
          },
          {
            "type": "object",
            "additionalProperties": false,
            "required": ["platform", "url"],
            "properties": {
              "platform": {
                "const": "hosted"
              },
              "url": {
                "type": "string",
                "format": "uri",
                "pattern": "^https://"
              },
              "label": {
                "type": "string",
                "minLength": 1,
                "maxLength": 40
              }
            }
          }
        ]
      }
    },
    "support": {
      "type": "array",
      "maxItems": 8,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["platform", "url"],
        "properties": {
          "platform": {
            "enum": ["patreon", "ko-fi", "github-sponsors", "open-collective", "custom"]
          },
          "url": {
            "type": "string",
            "format": "uri",
            "pattern": "^https://"
          },
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 40
          }
        }
      }
    },
    "hosting": {
      "type": "array",
      "maxItems": 4,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["name", "url"],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 48
          },
          "url": {
            "type": "string",
            "format": "uri",
            "pattern": "^https://"
          },
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 48
          }
        }
      }
    },
    "page": {
      "type": "object",
      "additionalProperties": false,
      "description": "Controls the order and explicit visibility of creator-configurable project-page sections.",
      "properties": {
        "sections": {
          "type": "array",
          "minItems": 4,
          "maxItems": 4,
          "uniqueItems": true,
          "default": ["quick-answer", "where-it-goes", "before-you-install", "about-project"],
          "items": {
            "enum": ["quick-answer", "where-it-goes", "before-you-install", "about-project"]
          }
        },
        "disabled": {
          "type": "array",
          "maxItems": 4,
          "uniqueItems": true,
          "default": [],
          "description": "Sections to hide explicitly. Omitting this property leaves every ordered section visible.",
          "items": {
            "enum": ["quick-answer", "where-it-goes", "before-you-install", "about-project"]
          }
        }
      }
    },
    "visibility": {
      "enum": ["listed", "hidden"],
      "default": "listed"
    }
  },
  "allOf": [
    {
      "if": {
        "required": ["preferredDownload"],
        "properties": {
          "preferredDownload": {
            "const": "curseforge"
          }
        }
      },
      "then": {
        "properties": {
          "projects": {
            "required": ["curseforge"]
          }
        }
      }
    },
    {
      "if": {
        "required": ["preferredDownload"],
        "properties": {
          "preferredDownload": {
            "const": "modrinth"
          }
        }
      },
      "then": {
        "properties": {
          "projects": {
            "required": ["modrinth"]
          }
        }
      }
    },
    {
      "if": {
        "required": ["preferredDownload"],
        "properties": {
          "preferredDownload": {
            "const": "github"
          }
        }
      },
      "then": {
        "required": ["destinations"],
        "properties": {
          "destinations": {
            "contains": {
              "type": "object",
              "required": ["platform", "releases"],
              "properties": {
                "platform": {
                  "const": "github"
                },
                "releases": {
                  "const": true
                }
              }
            }
          }
        }
      }
    }
  ]
}
