{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://suffect.com/schemas/0.2/manifest.schema.json",
  "title": "Suffect provider manifest 0.2",
  "description": "Served by a provider at https://{domain}/.well-known/suffect.json. 0.2 renames vendor to provider and adds resources[]. See docs/05.",
  "type": "object",
  "required": ["suffect", "provider", "terms"],
  "properties": {
    "suffect": {
      "type": "string",
      "pattern": "^0\\.2(\\.[0-9]+)?$"
    },
    "provider": {
      "type": "object",
      "required": ["name", "domain"],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "legal_name": {
          "type": "string"
        },
        "domain": {
          "$ref": "#/$defs/domain"
        },
        "support_url": {
          "type": "string",
          "format": "uri"
        },
        "kind": {
          "type": "string",
          "enum": ["vendor", "service", "house", "app"]
        }
      }
    },
    "terms": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/terms"
      }
    },
    "pricing": {
      "type": "object",
      "required": ["currency"],
      "properties": {
        "currency": {
          "$ref": "#/$defs/currency"
        },
        "plans": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/plan"
          }
        },
        "packs": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/pack"
          }
        },
        "url": {
          "type": "string",
          "format": "uri"
        }
      }
    },
    "signup": {
      "type": "object",
      "required": ["level"],
      "properties": {
        "level": {
          "type": "integer",
          "minimum": 0,
          "maximum": 4
        },
        "endpoint": {
          "type": "string",
          "format": "uri",
          "pattern": "^https://"
        },
        "auth": {
          "type": "string",
          "enum": ["suffect_jws"]
        },
        "contact_fields": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": ["email", "name", "country"]
          },
          "uniqueItems": true
        },
        "idempotency": {
          "type": "boolean"
        }
      }
    },
    "credential": {
      "type": "object",
      "required": ["type"],
      "properties": {
        "type": {
          "type": "string",
          "enum": ["api_key", "oauth_client"]
        },
        "header": {
          "type": "string"
        },
        "scheme": {
          "type": "string"
        },
        "scopes": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "rotation": {
          "type": "object",
          "required": ["supported"],
          "properties": {
            "supported": {
              "type": "boolean"
            },
            "endpoint": {
              "type": "string",
              "format": "uri",
              "pattern": "^https://"
            }
          }
        },
        "proxy_base_url": {
          "type": "string",
          "format": "uri",
          "pattern": "^https://"
        }
      }
    },
    "budget": {
      "type": "object",
      "properties": {
        "webhook": {
          "type": "string",
          "format": "uri",
          "pattern": "^https://"
        },
        "usage_events": {
          "type": "boolean"
        }
      }
    },
    "rails": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": ["card", "mpp", "x402"]
      },
      "uniqueItems": true
    },
    "contact": {
      "type": "object",
      "properties": {
        "security": {
          "type": "string",
          "format": "email"
        },
        "partnerships": {
          "type": "string",
          "format": "email"
        }
      }
    },
    "resources": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/resource"
      }
    }
  },
  "$defs": {
    "domain": {
      "type": "string",
      "pattern": "^([a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z]{2,63}$"
    },
    "currency": {
      "type": "string",
      "pattern": "^[A-Z]{3}$"
    },
    "sha256": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "terms": {
      "type": "object",
      "required": ["kind", "url", "version", "sha256"],
      "properties": {
        "kind": {
          "type": "string",
          "enum": ["terms_of_use", "privacy_policy", "acceptable_use", "other"]
        },
        "url": {
          "type": "string",
          "format": "uri",
          "pattern": "^https://"
        },
        "version": {
          "type": "string",
          "minLength": 1
        },
        "sha256": {
          "$ref": "#/$defs/sha256"
        },
        "effective": {
          "type": "string",
          "format": "date"
        },
        "requires": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": ["age_18", "authority_if_entity", "residency"]
          }
        },
        "notices": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "clauses": {
          "type": "array",
          "description": "The clauses the notices rest on, quoted from the document's normalized text; a clause's notice must be among this reference's notices.",
          "items": {
            "type": "object",
            "required": ["notice", "quote"],
            "additionalProperties": false,
            "properties": {
              "notice": {
                "type": "string",
                "minLength": 1
              },
              "section": {
                "type": "string",
                "maxLength": 40
              },
              "quote": {
                "type": "string",
                "minLength": 1,
                "maxLength": 600
              }
            }
          }
        }
      }
    },
    "plan": {
      "type": "object",
      "required": ["id", "name", "price", "period"],
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "price": {
          "type": "number",
          "minimum": 0
        },
        "period": {
          "type": "string",
          "enum": ["month", "year", "once"]
        },
        "credits": {
          "type": "number"
        }
      }
    },
    "pack": {
      "type": "object",
      "required": ["id", "price"],
      "properties": {
        "id": {
          "type": "string"
        },
        "credits": {
          "type": "number"
        },
        "price": {
          "type": "number",
          "minimum": 0
        },
        "expires_days": {
          "type": "integer",
          "minimum": 1
        },
        "requires_plan": {
          "type": "boolean"
        }
      }
    },
    "resource_kind": {
      "type": "string",
      "enum": ["account", "plan", "endpoint", "tool", "connection"]
    },
    "rail": {
      "type": "string",
      "enum": ["card", "x402", "mpp", "balance"]
    },
    "money": {
      "type": "object",
      "required": ["amount", "currency"],
      "properties": {
        "amount": {
          "type": "number",
          "minimum": 0
        },
        "currency": {
          "$ref": "#/$defs/currency"
        }
      }
    },
    "resource": {
      "type": "object",
      "required": ["kind", "slug", "name", "access", "pricing", "acquisition"],
      "properties": {
        "kind": {
          "$ref": "#/$defs/resource_kind"
        },
        "slug": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9-]{0,63}$"
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "description": {
          "type": "string"
        },
        "categories": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "access": {
          "type": "object",
          "required": ["auth"],
          "properties": {
            "auth": {
              "type": "string",
              "enum": ["api_key", "oauth2", "session", "payer", "internal"]
            },
            "base_url": {
              "type": "string",
              "format": "uri",
              "pattern": "^https://"
            },
            "path_prefix": {
              "type": "string",
              "pattern": "^/"
            },
            "header": {
              "type": "string"
            },
            "scheme": {
              "type": "string"
            },
            "scopes": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "pricing": {
          "type": "object",
          "required": ["model", "prices_before_call"],
          "properties": {
            "model": {
              "type": "string",
              "enum": ["free", "per_call", "per_unit", "subscription", "credits", "quote"]
            },
            "price": {
              "$ref": "#/$defs/money"
            },
            "unit": {
              "type": "string"
            },
            "period": {
              "type": "string",
              "enum": ["month", "week", "day", "once"]
            },
            "prices_before_call": {
              "type": "boolean"
            },
            "url": {
              "type": "string",
              "format": "uri"
            }
          }
        },
        "acquisition": {
          "type": "object",
          "required": ["method"],
          "properties": {
            "method": {
              "type": "string",
              "enum": ["playbook", "manifest", "oauth_connect", "none"]
            },
            "playbook": {
              "type": "string"
            },
            "endpoint": {
              "type": "string",
              "format": "uri",
              "pattern": "^https://"
            },
            "oauth": {
              "type": "object",
              "required": ["authorization_url", "token_url", "scopes"],
              "properties": {
                "authorization_url": {
                  "type": "string",
                  "format": "uri"
                },
                "token_url": {
                  "type": "string",
                  "format": "uri"
                },
                "scopes": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "terms": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/terms"
          }
        },
        "rails": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/rail"
          },
          "uniqueItems": true
        },
        "schema_ref": {
          "type": "string",
          "format": "uri"
        },
        "parent": {
          "type": "string"
        }
      }
    }
  }
}
