{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Affiliate Recommendation Package",
  "description": "Canonical output contract for the Affiliate Intelligence workflow. Defines the structured, compliant, human-approved recommendation package.",

  "type": "object",

  "properties": {
    "query": {
      "type": "string",
      "description": "The original user query or intent that triggered the affiliate workflow."
    },

    "match": {
      "type": "object",
      "description": "The selected affiliate match after deterministic routing.",
      "properties": {
        "affiliate_id": { "type": "string" },
        "name": { "type": "string" },
        "url": { "type": "string", "format": "uri" },
        "confidence": { "type": "number" },
        "reasoning": {
          "type": "object",
          "description": "Why this affiliate was selected, including scoring, penalties, and routing logic."
        }
      },
      "required": ["affiliate_id", "name", "url", "confidence"]
    },

    "compliance": {
      "type": "object",
      "description": "Compliance validation results from L3.",
      "properties": {
        "safe": { "type": "boolean" },
        "blocked_phrases": { "type": "array", "items": { "type": "string" } },
        "trigger_terms_detected": { "type": "array", "items": { "type": "string" } },
        "notes": { "type": "array", "items": { "type": "string" } }
      },
      "required": ["safe"]
    },

    "disclosure": {
      "type": "object",
      "description": "Disclosure text and placement guidance generated by L4.",
      "properties": {
        "required": { "type": "boolean" },
        "text": { "type": "string" },
        "placement_hint": { "type": "string" }
      },
      "required": ["required"]
    },

    "audit": {
      "type": "object",
      "description": "Audit metadata logged by L5.",
      "properties": {
        "timestamp": { "type": "string", "format": "date-time" },
        "human_approved": { "type": "boolean" },
        "approver": { "type": "string" },
        "event_id": { "type": "string" }
      },
      "required": ["timestamp", "human_approved"]
    }
  },

  "required": ["query", "match", "compliance", "disclosure", "audit"]
}
