{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Smarter Minds catalog item v1 — public read-only contract",
  "description": "Reference contract, not ACP or a provider feed. Readiness requires verification beyond schema validation.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "id",
    "type",
    "version",
    "title",
    "description",
    "contentLanguages",
    "format",
    "creatorIds",
    "publicationStatus",
    "canonicalUrls",
    "requirements",
    "deliverables",
    "rights",
    "commerce",
    "verification"
  ],
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9-]{1,79}$"
    },
    "type": {
      "enum": [
        "experience",
        "book-edition"
      ]
    },
    "version": {
      "type": "string",
      "minLength": 1
    },
    "title": {
      "type": "object",
      "required": [
        "es",
        "en"
      ],
      "additionalProperties": false,
      "properties": {
        "es": {
          "type": "string",
          "minLength": 1
        },
        "en": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "description": {
      "type": "object",
      "required": [
        "es",
        "en"
      ],
      "additionalProperties": false,
      "properties": {
        "es": {
          "type": "string",
          "minLength": 1
        },
        "en": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "contentLanguages": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "enum": [
          "es",
          "en"
        ]
      }
    },
    "format": {
      "type": [
        "string",
        "null"
      ]
    },
    "creatorIds": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "uniqueItems": true
    },
    "publicationStatus": {
      "enum": [
        "draft",
        "published",
        "retired"
      ]
    },
    "canonicalUrls": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "es",
        "en"
      ],
      "properties": {
        "es": {
          "anyOf": [
            {
              "type": "string",
              "format": "uri",
              "pattern": "^https://"
            },
            {
              "type": "null"
            }
          ]
        },
        "en": {
          "anyOf": [
            {
              "type": "string",
              "format": "uri",
              "pattern": "^https://"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "requirements": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "browserJavascript",
        "account",
        "durationMinutes"
      ],
      "properties": {
        "browserJavascript": {
          "type": [
            "boolean",
            "null"
          ]
        },
        "account": {
          "type": [
            "boolean",
            "null"
          ]
        },
        "durationMinutes": {
          "type": [
            "number",
            "null"
          ],
          "exclusiveMinimum": 0
        }
      }
    },
    "deliverables": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "es",
          "en"
        ],
        "additionalProperties": false,
        "properties": {
          "es": {
            "type": "string",
            "minLength": 1
          },
          "en": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "rights": {
      "type": "object",
      "required": [
        "status",
        "termsUrl",
        "summary"
      ],
      "additionalProperties": false,
      "properties": {
        "status": {
          "enum": [
            "pending",
            "verified"
          ]
        },
        "termsUrl": {
          "anyOf": [
            {
              "type": "string",
              "format": "uri",
              "pattern": "^https://"
            },
            {
              "type": "null"
            }
          ]
        },
        "summary": {
          "type": "object",
          "required": [
            "es",
            "en"
          ],
          "additionalProperties": false,
          "properties": {
            "es": {
              "type": "string",
              "minLength": 1
            },
            "en": {
              "type": "string",
              "minLength": 1
            }
          }
        }
      }
    },
    "commerce": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "integratedCheckout",
        "offers"
      ],
      "properties": {
        "mode": {
          "enum": [
            "not-available",
            "free-access",
            "external-retailer"
          ]
        },
        "integratedCheckout": {
          "const": false
        },
        "offers": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "seller",
              "editionId",
              "url",
              "format",
              "price",
              "currency",
              "territories",
              "checkedAt",
              "validUntil",
              "verificationStatus"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "seller": {
                "type": "string",
                "minLength": 1
              },
              "editionId": {
                "type": "string"
              },
              "url": {
                "type": "string",
                "format": "uri",
                "pattern": "^https://"
              },
              "format": {
                "type": "string",
                "minLength": 1
              },
              "price": {
                "anyOf": [
                  {
                    "type": "string",
                    "pattern": "^[0-9]+(\\.[0-9]{2})?$"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "currency": {
                "anyOf": [
                  {
                    "type": "string",
                    "pattern": "^[A-Z]{3}$"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "territories": {
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^[A-Z]{2}$"
                }
              },
              "checkedAt": {
                "type": "string",
                "format": "date-time"
              },
              "validUntil": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "verificationStatus": {
                "const": "verified"
              }
            },
            "allOf": [
              {
                "if": {
                  "properties": {
                    "price": {
                      "type": "string"
                    }
                  }
                },
                "then": {
                  "properties": {
                    "currency": {
                      "type": "string",
                      "pattern": "^[A-Z]{3}$"
                    },
                    "validUntil": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            ]
          }
        }
      }
    },
    "verification": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "checkedAt",
        "publicEvidenceUrl"
      ],
      "properties": {
        "status": {
          "enum": [
            "pending",
            "verified"
          ]
        },
        "checkedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "publicEvidenceUrl": {
          "anyOf": [
            {
              "type": "string",
              "format": "uri",
              "pattern": "^https://"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "publicationStatus": {
            "const": "published"
          }
        }
      },
      "then": {
        "properties": {
          "canonicalUrls": {
            "properties": {
              "es": {
                "type": "string",
                "format": "uri",
                "pattern": "^https://"
              },
              "en": {
                "type": "string",
                "format": "uri",
                "pattern": "^https://"
              }
            }
          },
          "verification": {
            "properties": {
              "status": {
                "const": "verified"
              },
              "checkedAt": {
                "type": "string",
                "format": "date-time"
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "commerce": {
            "properties": {
              "mode": {
                "const": "external-retailer"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "commerce": {
            "properties": {
              "offers": {
                "minItems": 1
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "commerce": {
            "properties": {
              "mode": {
                "const": "not-available"
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "commerce": {
            "properties": {
              "offers": {
                "maxItems": 0
              }
            }
          }
        }
      }
    }
  ]
}
