{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tenantatlas.local/schemas/shared-fixture-profile.schema.json",
  "title": "SharedFixtureProfileCatalog",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "version",
    "defaultProfile",
    "profiles",
    "helperBindings",
    "auditedFactories",
    "migrationPacks"
  ],
  "properties": {
    "version": {
      "type": "integer",
      "minimum": 1
    },
    "defaultProfile": {
      "type": "string",
      "const": "minimal"
    },
    "profiles": {
      "type": "array",
      "minItems": 3,
      "items": {
        "$ref": "#/$defs/profile"
      },
      "allOf": [
        {
          "contains": {
            "type": "object",
            "required": ["id"],
            "properties": {
              "id": {
                "const": "minimal"
              }
            }
          }
        },
        {
          "contains": {
            "type": "object",
            "required": ["id"],
            "properties": {
              "id": {
                "const": "standard"
              }
            }
          }
        },
        {
          "contains": {
            "type": "object",
            "required": ["id"],
            "properties": {
              "id": {
                "const": "full"
              }
            }
          }
        }
      ]
    },
    "helperBindings": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/helperBinding"
      }
    },
    "auditedFactories": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/auditedFactory"
      }
    },
    "migrationPacks": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/migrationPack"
      }
    }
  },
  "$defs": {
    "profile": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "costClass",
        "notes",
        "sideEffects"
      ],
      "properties": {
        "id": {
          "type": "string",
          "enum": [
            "minimal",
            "standard",
            "full"
          ]
        },
        "costClass": {
          "type": "string",
          "enum": [
            "minimal",
            "standard",
            "integration-heavy"
          ]
        },
        "legacyAliases": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        },
        "notes": {
          "type": "string",
          "minLength": 1
        },
        "sideEffects": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "workspace",
            "workspaceMembership",
            "tenantMembership",
            "session",
            "cache",
            "providerConnection",
            "providerCredential",
            "uiContext"
          ],
          "properties": {
            "workspace": {
              "type": "boolean"
            },
            "workspaceMembership": {
              "type": "boolean"
            },
            "tenantMembership": {
              "type": "boolean"
            },
            "session": {
              "type": "boolean"
            },
            "cache": {
              "type": "boolean"
            },
            "providerConnection": {
              "type": "boolean"
            },
            "providerCredential": {
              "type": "boolean"
            },
            "uiContext": {
              "type": "boolean"
            }
          }
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "id": {
                "const": "minimal"
              }
            }
          },
          "then": {
            "properties": {
              "costClass": {
                "const": "minimal"
              },
              "sideEffects": {
                "properties": {
                  "providerConnection": {
                    "const": false
                  },
                  "providerCredential": {
                    "const": false
                  },
                  "cache": {
                    "const": false
                  },
                  "uiContext": {
                    "const": false
                  }
                }
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "id": {
                "const": "full"
              }
            }
          },
          "then": {
            "properties": {
              "costClass": {
                "const": "integration-heavy"
              }
            }
          }
        }
      ]
    },
    "helperBinding": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "helperName",
        "defaultProfile",
        "supportedProfiles",
        "transitionStatus"
      ],
      "properties": {
        "helperName": {
          "type": "string",
          "minLength": 1
        },
        "defaultProfile": {
          "type": "string",
          "enum": [
            "minimal",
            "standard",
            "full"
          ]
        },
        "supportedProfiles": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "enum": [
              "minimal",
              "standard",
              "full"
            ]
          },
          "uniqueItems": true
        },
        "legacyAliases": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        },
        "legacyAliasResolutions": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/legacyAliasResolution"
          }
        },
        "transitionStatus": {
          "type": "string",
          "enum": [
            "current",
            "legacy-transition",
            "planned-removal"
          ]
        },
        "removalTrigger": {
          "type": "string",
          "minLength": 1
        },
        "announcesHeavyContext": {
          "type": "boolean"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "transitionStatus": {
                "enum": [
                  "legacy-transition",
                  "planned-removal"
                ]
              }
            }
          },
          "then": {
            "required": [
              "removalTrigger"
            ]
          }
        }
      ]
    },
    "legacyAliasResolution": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "alias",
        "resolvedProfile",
        "removalTrigger"
      ],
      "properties": {
        "alias": {
          "type": "string",
          "minLength": 1
        },
        "resolvedProfile": {
          "type": "string",
          "enum": [
            "minimal",
            "standard",
            "full"
          ]
        },
        "removalTrigger": {
          "type": "string",
          "minLength": 1
        },
        "sideEffectOverrides": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "workspace": {
              "type": "boolean"
            },
            "workspaceMembership": {
              "type": "boolean"
            },
            "tenantMembership": {
              "type": "boolean"
            },
            "session": {
              "type": "boolean"
            },
            "cache": {
              "type": "boolean"
            },
            "providerConnection": {
              "type": "boolean"
            },
            "providerCredential": {
              "type": "boolean"
            },
            "uiContext": {
              "type": "boolean"
            }
          }
        }
      }
    },
    "auditedFactory": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "factoryName",
        "defaultCostClass",
        "cascadeFindings"
      ],
      "properties": {
        "factoryName": {
          "type": "string",
          "minLength": 1
        },
        "defaultCostClass": {
          "type": "string",
          "enum": [
            "minimal",
            "standard",
            "integration-heavy"
          ]
        },
        "leanStates": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        },
        "heavyStates": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        },
        "cascadeFindings": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/cascadeFinding"
          }
        }
      }
    },
    "cascadeFinding": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source",
        "triggerCondition",
        "createdObjects",
        "disposition"
      ],
      "properties": {
        "source": {
          "type": "string",
          "enum": [
            "definition",
            "attribute-callback",
            "afterCreating",
            "model-event",
            "support-helper"
          ]
        },
        "triggerCondition": {
          "type": "string",
          "minLength": 1
        },
        "createdObjects": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        },
        "disposition": {
          "type": "string",
          "enum": [
            "remove",
            "make-explicit",
            "retain-documented",
            "follow-up"
          ]
        },
        "notes": {
          "type": "string"
        }
      }
    },
    "migrationPack": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "packId",
        "targetLanes",
        "selectionBasis",
        "callerSelectors",
        "targetProfile"
      ],
      "properties": {
        "packId": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
        },
        "targetLanes": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "enum": [
              "fast-feedback",
              "confidence",
              "browser",
              "heavy-governance"
            ]
          },
          "uniqueItems": true
        },
        "selectionBasis": {
          "type": "string",
          "enum": [
            "high-usage",
            "high-cost",
            "shared-surface",
            "legacy-dependency"
          ]
        },
        "callerSelectors": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string"
          }
        },
        "targetProfile": {
          "type": "string",
          "enum": [
            "minimal",
            "standard",
            "full"
          ]
        },
        "legacyFallbackAllowed": {
          "type": "boolean"
        },
        "expectedLaneImpact": {
          "type": "string"
        }
      }
    }
  }
}