{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://g-hubs.com/extension-docs/g-hubs-personal-homepage-config.schema.json",
  "title": "G-Hubs Personal Homepage Config (v1)",
  "description": "Import and cloud-sync compatible schema for G-Hubs New Tab and Web /newtab personal homepage configs. Keep total serialized UTF-8 payload <= 65536 bytes (64 KiB) for cloud sync.",
  "$comment": "Cross-field rules enforced by backend validator: (1) all IDs in folders, shortcuts, search.engines, and search.history must be unique; (2) every non-null shortcut.folderId must reference an existing folder.id; (3) search.defaultEngineId and every search.history[].engineId must reference an existing search.engines[].id; (4) total PUT payload size <= 65536 bytes (64 KiB).",
  "type": "object",
  "additionalProperties": false,
  "required": ["version", "shortcuts", "folders", "settings", "search", "updatedAt"],
  "properties": {
    "version": {
      "const": 1
    },
    "shortcuts": {
      "type": "array",
      "maxItems": 200,
      "items": {
        "$ref": "#/$defs/shortcut"
      }
    },
    "folders": {
      "type": "array",
      "maxItems": 50,
      "items": {
        "$ref": "#/$defs/folder"
      }
    },
    "settings": {
      "$ref": "#/$defs/settings"
    },
    "search": {
      "$ref": "#/$defs/search"
    },
    "updatedAt": {
      "$ref": "#/$defs/utcIsoDateTime"
    }
  },
  "$defs": {
    "nonEmptyId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 80,
      "pattern": "\\S"
    },
    "nullableNonEmptyId": {
      "oneOf": [
        { "type": "null" },
        { "$ref": "#/$defs/nonEmptyId" }
      ]
    },
    "nullableAssetKey": {
      "oneOf": [
        { "type": "null" },
        { "type": "string", "minLength": 1, "maxLength": 512, "pattern": "\\S" }
      ]
    },
    "nullableFeaturedCategory": {
      "oneOf": [
        { "type": "null" },
        { "type": "string", "minLength": 1, "maxLength": 64, "pattern": "\\S" }
      ]
    },
    "nullableFeaturedQuery": {
      "oneOf": [
        { "type": "null" },
        { "type": "string", "minLength": 1, "maxLength": 100, "pattern": "\\S" }
      ]
    },
    "utcIsoDateTime": {
      "type": "string",
      "maxLength": 40,
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$"
    },
    "nullableUtcIsoDateTime": {
      "oneOf": [
        { "type": "null" },
        { "$ref": "#/$defs/utcIsoDateTime" }
      ]
    },
    "httpUrl": {
      "type": "string",
      "minLength": 8,
      "maxLength": 2048,
      "pattern": "^https?://.+"
    },
    "nullableHttpUrl": {
      "oneOf": [
        { "type": "null" },
        { "$ref": "#/$defs/httpUrl" }
      ]
    },
    "nullableHexColor": {
      "oneOf": [
        { "type": "null" },
        { "type": "string", "pattern": "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$" }
      ]
    },
    "nullableCustomHexColor": {
      "oneOf": [
        { "type": "null" },
        { "type": "string", "pattern": "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$" }
      ]
    },
    "shortcut": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "source",
        "siteId",
        "favoriteId",
        "title",
        "url",
        "iconUrl",
        "iconType",
        "iconSource",
        "uploadedIconAssetKey",
        "folderId",
        "order",
        "openInNewTab",
        "iconResolvedAt",
        "iconResolutionAttemptedAt",
        "createdAt",
        "updatedAt"
      ],
      "properties": {
        "id": { "$ref": "#/$defs/nonEmptyId" },
        "source": { "enum": ["preset", "ghubs", "manual", "favorite"] },
        "siteId": { "$ref": "#/$defs/nullableNonEmptyId" },
        "favoriteId": { "$ref": "#/$defs/nullableNonEmptyId" },
        "title": { "type": "string", "minLength": 1, "maxLength": 80, "pattern": "\\S" },
        "url": { "$ref": "#/$defs/httpUrl" },
        "iconUrl": { "$ref": "#/$defs/nullableHttpUrl" },
        "iconType": { "enum": ["favicon", "preset", "custom"] },
        "iconSource": {
          "enum": ["uploaded", "custom", "site-logo", "site-icon", "favicon", "fallback"]
        },
        "uploadedIconAssetKey": { "$ref": "#/$defs/nullableAssetKey" },
        "folderId": { "$ref": "#/$defs/nullableNonEmptyId" },
        "order": { "type": "integer", "minimum": 0, "maximum": 10000 },
        "openInNewTab": { "const": true },
        "iconResolvedAt": { "$ref": "#/$defs/nullableUtcIsoDateTime" },
        "iconResolutionAttemptedAt": { "$ref": "#/$defs/nullableUtcIsoDateTime" },
        "createdAt": { "$ref": "#/$defs/utcIsoDateTime" },
        "updatedAt": { "$ref": "#/$defs/utcIsoDateTime" }
      }
    },
    "folder": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name", "order", "createdAt", "updatedAt"],
      "properties": {
        "id": { "$ref": "#/$defs/nonEmptyId" },
        "name": { "type": "string", "minLength": 1, "maxLength": 80, "pattern": "\\S" },
        "order": { "type": "integer", "minimum": 0, "maximum": 10000 },
        "createdAt": { "$ref": "#/$defs/utcIsoDateTime" },
        "updatedAt": { "$ref": "#/$defs/utcIsoDateTime" }
      }
    },
    "background": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "imageUrl",
        "uploadedAssetKey",
        "color",
        "gradientFrom",
        "gradientTo",
        "gradientAngle",
        "fit",
        "dim",
        "blur"
      ],
      "properties": {
        "mode": {
          "enum": ["solid", "gradient", "url", "featured", "uploaded", "default"],
          "$comment": "Prefer featured, solid, gradient, or url for newly authored or AI-generated configs."
        },
        "imageUrl": { "$ref": "#/$defs/nullableHttpUrl" },
        "uploadedAssetKey": { "$ref": "#/$defs/nullableAssetKey" },
        "color": { "$ref": "#/$defs/nullableHexColor" },
        "gradientFrom": { "$ref": "#/$defs/nullableHexColor" },
        "gradientTo": { "$ref": "#/$defs/nullableHexColor" },
        "gradientAngle": { "type": "integer", "minimum": 0, "maximum": 360 },
        "fit": { "enum": ["cover", "contain"] },
        "dim": { "type": "integer", "minimum": 0, "maximum": 80 },
        "blur": { "type": "integer", "minimum": 0, "maximum": 24 },
        "featuredSource": {
          "oneOf": [
            { "type": "null" },
            { "enum": ["all", "unsplash", "bing", "wallhaven"] }
          ]
        },
        "featuredCategory": { "$ref": "#/$defs/nullableFeaturedCategory" },
        "featuredCustomQuery": { "$ref": "#/$defs/nullableFeaturedQuery" }
      },
      "allOf": [
        {
          "if": { "properties": { "mode": { "const": "default" } } },
          "then": {
            "properties": {
              "imageUrl": { "type": "null" },
              "uploadedAssetKey": { "type": "null" },
              "color": { "type": "null" },
              "gradientFrom": { "type": "null" },
              "gradientTo": { "type": "null" }
            }
          }
        },
        {
          "if": { "properties": { "mode": { "const": "solid" } } },
          "then": {
            "properties": {
              "color": { "type": "string", "pattern": "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$" },
              "imageUrl": { "type": "null" },
              "uploadedAssetKey": { "type": "null" },
              "gradientFrom": { "type": "null" },
              "gradientTo": { "type": "null" }
            }
          }
        },
        {
          "if": { "properties": { "mode": { "const": "gradient" } } },
          "then": {
            "properties": {
              "gradientFrom": { "type": "string", "pattern": "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$" },
              "gradientTo": { "type": "string", "pattern": "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$" },
              "imageUrl": { "type": "null" },
              "uploadedAssetKey": { "type": "null" },
              "color": { "type": "null" }
            }
          }
        },
        {
          "if": { "properties": { "mode": { "enum": ["url", "featured"] } } },
          "then": {
            "properties": {
              "imageUrl": { "$ref": "#/$defs/httpUrl" },
              "uploadedAssetKey": { "type": "null" },
              "color": { "type": "null" },
              "gradientFrom": { "type": "null" },
              "gradientTo": { "type": "null" }
            }
          }
        },
        {
          "if": { "properties": { "mode": { "const": "uploaded" } } },
          "then": {
            "properties": {
              "imageUrl": { "$ref": "#/$defs/httpUrl" },
              "uploadedAssetKey": {
                "type": "string",
                "minLength": 28,
                "maxLength": 512,
                "pattern": "^banners/homepage-backgrounds/\\S+"
              },
              "color": { "type": "null" },
              "gradientFrom": { "type": "null" },
              "gradientTo": { "type": "null" }
            }
          }
        }
      ]
    },
    "settings": {
      "type": "object",
      "additionalProperties": false,
      "required": ["columns", "iconSize", "showTitle", "openMode", "background"],
      "properties": {
        "columns": { "type": "integer", "minimum": 1, "maximum": 12 },
        "iconSize": { "enum": ["sm", "md", "lg"] },
        "showTitle": { "type": "boolean" },
        "openMode": { "enum": ["new-tab", "same-tab"] },
        "autoHideControls": { "type": "boolean" },
        "background": { "$ref": "#/$defs/background" },
        "shortcuts": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "titleColor": { "$ref": "#/$defs/nullableCustomHexColor" },
            "borderRadius": { "type": "integer", "minimum": 0, "maximum": 100 }
          }
        },
        "searchBar": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "opacity": { "type": "integer", "minimum": 0, "maximum": 100 },
            "backgroundColor": { "$ref": "#/$defs/nullableCustomHexColor" },
            "width": { "type": "integer", "minimum": 360, "maximum": 1000 },
            "topOffset": { "type": "integer", "minimum": 20, "maximum": 50 },
            "borderRadius": { "type": "integer", "minimum": 1, "maximum": 100 },
            "shadow": { "enum": ["none", "sm", "md", "lg"] },
            "showEngineIcon": { "type": "boolean" },
            "showSubmitIcon": { "type": "boolean" },
            "showHistory": { "type": "boolean" }
          }
        },
        "folder": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "opacity": { "type": "integer", "minimum": 10, "maximum": 100 },
            "backgroundColor": { "$ref": "#/$defs/nullableCustomHexColor" },
            "showTitle": { "type": "boolean" }
          }
        }
      }
    },
    "searchEngine": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "name",
        "template",
        "iconUrl",
        "iconMode",
        "createdAt",
        "updatedAt"
      ],
      "properties": {
        "id": { "$ref": "#/$defs/nonEmptyId" },
        "name": { "type": "string", "minLength": 1, "maxLength": 80, "pattern": "\\S" },
        "template": {
          "type": "string",
          "minLength": 15,
          "maxLength": 2048,
          "pattern": "^https?://.*\\{query\\}.*"
        },
        "iconUrl": { "$ref": "#/$defs/nullableHttpUrl" },
        "iconMode": { "enum": ["auto", "custom"] },
        "iconSource": {
          "enum": ["custom", "site-logo", "site-icon", "favicon", "fallback"]
        },
        "iconResolvedAt": { "$ref": "#/$defs/nullableUtcIsoDateTime" },
        "iconResolutionAttemptedAt": { "$ref": "#/$defs/nullableUtcIsoDateTime" },
        "createdAt": { "$ref": "#/$defs/utcIsoDateTime" },
        "updatedAt": { "$ref": "#/$defs/utcIsoDateTime" }
      }
    },
    "searchHistory": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "query", "engineId", "engineName", "searchedAt"],
      "properties": {
        "id": { "$ref": "#/$defs/nonEmptyId" },
        "query": { "type": "string", "minLength": 1, "maxLength": 200, "pattern": "\\S" },
        "engineId": { "$ref": "#/$defs/nonEmptyId" },
        "engineName": { "type": "string", "minLength": 1, "maxLength": 80, "pattern": "\\S" },
        "searchedAt": { "$ref": "#/$defs/utcIsoDateTime" }
      }
    },
    "search": {
      "type": "object",
      "additionalProperties": false,
      "required": ["defaultEngineId", "engines", "history"],
      "properties": {
        "defaultEngineId": { "$ref": "#/$defs/nonEmptyId" },
        "engines": {
          "type": "array",
          "minItems": 1,
          "maxItems": 20,
          "items": { "$ref": "#/$defs/searchEngine" }
        },
        "history": {
          "type": "array",
          "maxItems": 50,
          "items": { "$ref": "#/$defs/searchHistory" }
        }
      }
    }
  }
}
