{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.cuddler.dev/standards/artifact-definitions/portal-page-factory-plan/1.0.0/data.schema.json",
  "title": "Portal Page Factory Plan",
  "for-ai": [
    {
      "instruction": "Summarize when an AI consumer should use this Artifact Definition.",
      "input": "",
      "output": "Use the Portal Page Factory Plan Artifact Definition to validate structured implementation plans for portal page synchronization, evidence capture, capabilities, and completion tracking."
    }
  ],
  "type": "object",
  "additionalProperties": false,
  "required": [
    "$schema",
    "Status",
    "Next Step",
    "meta",
    "source",
    "pageSync",
    "evidence",
    "capabilities",
    "implementation"
  ],
  "properties": {
    "$schema": {
      "const": "https://www.cuddler.dev/standards/artifact-definitions/portal-page-factory-plan/1.0.0/data.schema.json"
    },
    "Status": {
      "enum": [
        "Draft",
        "Ready",
        "InProgress",
        "Blocked",
        "Complete"
      ]
    },
    "Next Step": {
      "type": "string",
      "maxLength": 500
    },
    "meta": {
      "$ref": "#/$defs/meta"
    },
    "source": {
      "$ref": "#/$defs/source"
    },
    "pageSync": {
      "$ref": "#/$defs/pageSync"
    },
    "evidence": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/evidence"
      }
    },
    "capabilities": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/capability"
      }
    },
    "implementation": {
      "$ref": "#/$defs/implementation"
    },
    "completion": {
      "$ref": "#/$defs/completion"
    }
  },
  "$defs": {
    "meta": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schemaVersion",
        "documentTypeId",
        "documentId",
        "title",
        "createdAt",
        "authors"
      ],
      "properties": {
        "schemaVersion": {
          "const": "1.0.0"
        },
        "documentTypeId": {
          "const": "portal-page-factory-plan"
        },
        "documentId": {
          "type": "string",
          "format": "uuid"
        },
        "title": {
          "type": "string",
          "minLength": 1
        },
        "createdAt": {
          "type": "string",
          "format": "date-time"
        },
        "updatedAt": {
          "type": "string",
          "format": "date-time"
        },
        "authors": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "name"
            ],
            "properties": {
              "name": {
                "type": "string",
                "minLength": 1
              }
            }
          }
        },
        "summary": {
          "type": "string"
        }
      }
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "originalInput",
        "normalizedRoute",
        "module",
        "catalogPath",
        "catalogPageId",
        "pageArtifactPath",
        "planArtifactPath",
        "templateId"
      ],
      "properties": {
        "originalInput": {
          "type": "string",
          "minLength": 1
        },
        "normalizedRoute": {
          "type": "string",
          "pattern": "^/"
        },
        "module": {
          "type": "string",
          "minLength": 1
        },
        "catalogPath": {
          "type": "string",
          "minLength": 1
        },
        "catalogPageId": {
          "type": "string",
          "minLength": 1
        },
        "pageArtifactPath": {
          "type": "string",
          "pattern": "\\.json$"
        },
        "planArtifactPath": {
          "type": "string",
          "pattern": "\\.plan\\.json$"
        },
        "templateId": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "pageSync": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "pageDocumentId",
        "routeTemplates",
        "pageTemplateAnnotation",
        "currentPageSha256",
        "pageUpdatedAt"
      ],
      "properties": {
        "pageDocumentId": {
          "type": "string",
          "minLength": 1
        },
        "routeTemplates": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "pattern": "^/"
          }
        },
        "pageTemplateAnnotation": {
          "type": "string",
          "minLength": 1
        },
        "currentPageSha256": {
          "$ref": "#/$defs/sha256"
        },
        "pageUpdatedAt": {
          "type": "string"
        }
      }
    },
    "evidence": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kind",
        "source",
        "summary"
      ],
      "properties": {
        "kind": {
          "enum": [
            "current",
            "git-history",
            "legacy-primary",
            "legacy-secondary",
            "adjacent-pattern",
            "blocked"
          ]
        },
        "source": {
          "type": "string",
          "minLength": 1
        },
        "summary": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "capability": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "title",
        "status",
        "evidence",
        "currentState",
        "targetRestore",
        "uiSchema",
        "apiContract",
        "backend",
        "tests"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "title": {
          "type": "string",
          "minLength": 1
        },
        "status": {
          "enum": [
            "restore-now",
            "already-restored",
            "mvp-omit",
            "deprecated",
            "blocked",
            "product-decision-required"
          ]
        },
        "evidence": {
          "type": "string",
          "minLength": 1
        },
        "currentState": {
          "type": "string",
          "minLength": 1
        },
        "targetRestore": {
          "type": "string",
          "minLength": 1
        },
        "uiSchema": {
          "type": "string",
          "minLength": 1
        },
        "apiContract": {
          "type": "string",
          "minLength": 1
        },
        "backend": {
          "type": "string",
          "minLength": 1
        },
        "tests": {
          "type": "string",
          "minLength": 1
        },
        "blocker": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "reason",
            "requiredWork",
            "owner"
          ],
          "properties": {
            "reason": {
              "type": "string",
              "minLength": 1
            },
            "requiredWork": {
              "type": "string",
              "minLength": 1
            },
            "owner": {
              "type": "string",
              "minLength": 1
            }
          }
        }
      }
    },
    "implementation": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "uiSchema",
        "runtimeUi",
        "apiContracts",
        "application",
        "domainInfrastructurePersistence",
        "tests",
        "validation"
      ],
      "properties": {
        "uiSchema": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "runtimeUi": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "apiContracts": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "application": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "domainInfrastructurePersistence": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "tests": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "validation": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string"
          }
        }
      }
    },
    "completion": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "completedAt",
        "finalPageSha256",
        "validationCommands",
        "testCommands"
      ],
      "properties": {
        "completedAt": {
          "type": "string",
          "format": "date-time"
        },
        "finalPageSha256": {
          "$ref": "#/$defs/sha256"
        },
        "validationCommands": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "testCommands": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "sha256": {
      "type": "string",
      "pattern": "^[A-Fa-f0-9]{64}$"
    }
  }
}
