{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://maestrogtm.com/schemas/linkedin-text-ad-record.v1.json",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "contract_version",
    "revision",
    "fingerprint",
    "inputs",
    "evaluation",
    "variants",
    "test_handoff",
    "sources",
    "requests",
    "review"
  ],
  "properties": {
    "schema_version": {
      "const": "maestro.linkedin-text-ads.record.v1"
    },
    "contract_version": {
      "type": "string",
      "minLength": 1
    },
    "revision": {
      "type": "integer",
      "minimum": 1
    },
    "fingerprint": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "inputs": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "offer",
        "buyer",
        "objective",
        "desktop_audience_fit",
        "compact_message_fit",
        "approved_claims",
        "image",
        "destination_url",
        "audience",
        "audience_permission",
        "learning_goal",
        "bid_basis",
        "bid_basis_reason",
        "spend_ceiling",
        "conversion_definition",
        "stop_conditions",
        "owner",
        "open_questions"
      ],
      "properties": {
        "offer": {
          "type": "string"
        },
        "buyer": {
          "type": "string"
        },
        "objective": {
          "enum": [
            "brand_awareness",
            "website_visits",
            "engagement",
            "website_conversions",
            "other",
            "unknown"
          ]
        },
        "desktop_audience_fit": {
          "type": [
            "boolean",
            "null"
          ]
        },
        "compact_message_fit": {
          "type": [
            "boolean",
            "null"
          ]
        },
        "approved_claims": {
          "type": "array",
          "minItems": 0,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "claim_id",
              "verbatim_text",
              "source_ref",
              "permission"
            ],
            "properties": {
              "claim_id": {
                "type": "string",
                "minLength": 1
              },
              "verbatim_text": {
                "type": "string",
                "minLength": 1
              },
              "source_ref": {
                "type": "string",
                "minLength": 1
              },
              "permission": {
                "enum": [
                  "approved",
                  "denied",
                  "unknown"
                ]
              }
            }
          }
        },
        "image": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "asset_id",
            "declared_mime",
            "sniffed_mime",
            "decoded_width",
            "decoded_height",
            "byte_length",
            "sha256",
            "full_decode_valid"
          ],
          "properties": {
            "asset_id": {
              "type": "string",
              "minLength": 1
            },
            "declared_mime": {
              "enum": [
                "image/png",
                "image/jpeg"
              ]
            },
            "sniffed_mime": {
              "enum": [
                "image/png",
                "image/jpeg",
                "unknown"
              ]
            },
            "decoded_width": {
              "type": [
                "integer",
                "null"
              ]
            },
            "decoded_height": {
              "type": [
                "integer",
                "null"
              ]
            },
            "byte_length": {
              "type": "integer",
              "minimum": 0
            },
            "sha256": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            },
            "full_decode_valid": {
              "type": "boolean"
            }
          }
        },
        "destination_url": {
          "type": "string"
        },
        "audience": {
          "type": "string"
        },
        "audience_permission": {
          "enum": [
            "confirmed",
            "denied",
            "unknown"
          ]
        },
        "learning_goal": {
          "type": "string"
        },
        "bid_basis": {
          "enum": [
            "cpc",
            "cpm",
            "unknown"
          ]
        },
        "bid_basis_reason": {
          "type": "string"
        },
        "spend_ceiling": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "amount",
            "currency",
            "period"
          ],
          "properties": {
            "amount": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0
            },
            "currency": {
              "type": "string"
            },
            "period": {
              "type": "string"
            }
          }
        },
        "conversion_definition": {
          "type": "string"
        },
        "stop_conditions": {
          "type": "array",
          "minItems": 0,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "condition_id",
              "metric",
              "operator",
              "threshold",
              "window",
              "action"
            ],
            "properties": {
              "condition_id": {
                "type": "string"
              },
              "metric": {
                "type": "string"
              },
              "operator": {
                "enum": [
                  "lt",
                  "lte",
                  "eq",
                  "gte",
                  "gt",
                  "missing"
                ]
              },
              "threshold": {
                "type": [
                  "number",
                  "string",
                  "null"
                ]
              },
              "window": {
                "type": "string"
              },
              "action": {
                "type": "string"
              }
            }
          }
        },
        "owner": {
          "type": "string"
        },
        "open_questions": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "evaluation": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "format_decision",
        "format_reason_code",
        "format_reason",
        "handoff_readiness",
        "readiness_reason_code",
        "readiness_reason",
        "next_action"
      ],
      "properties": {
        "format_decision": {
          "enum": [
            "use",
            "hold",
            "another_format"
          ]
        },
        "format_reason_code": {
          "type": "string",
          "minLength": 1
        },
        "format_reason": {
          "type": "string",
          "minLength": 1
        },
        "handoff_readiness": {
          "enum": [
            "draft",
            "launch_hold",
            "launch_ready"
          ]
        },
        "readiness_reason_code": {
          "type": "string",
          "minLength": 1
        },
        "readiness_reason": {
          "type": "string",
          "minLength": 1
        },
        "next_action": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "variants": {
      "type": "array",
      "minItems": 0,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "variant_id",
          "route_label",
          "headline",
          "description",
          "headline_counts",
          "description_counts",
          "claim_source_ids",
          "semantic_support"
        ],
        "properties": {
          "variant_id": {
            "type": "string",
            "minLength": 1
          },
          "route_label": {
            "type": "string",
            "minLength": 1
          },
          "headline": {
            "type": "string",
            "minLength": 1
          },
          "description": {
            "type": "string",
            "minLength": 1
          },
          "headline_counts": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "code_points",
              "utf16_units",
              "enforced"
            ],
            "properties": {
              "code_points": {
                "type": "integer",
                "minimum": 0
              },
              "utf16_units": {
                "type": "integer",
                "minimum": 0
              },
              "enforced": {
                "type": "integer",
                "minimum": 0
              }
            }
          },
          "description_counts": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "code_points",
              "utf16_units",
              "enforced"
            ],
            "properties": {
              "code_points": {
                "type": "integer",
                "minimum": 0
              },
              "utf16_units": {
                "type": "integer",
                "minimum": 0
              },
              "enforced": {
                "type": "integer",
                "minimum": 0
              }
            }
          },
          "claim_source_ids": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "string",
              "minLength": 1
            }
          },
          "semantic_support": {
            "enum": [
              "supported",
              "unsupported",
              "needs_review"
            ]
          }
        }
      }
    },
    "test_handoff": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "objective",
        "audience",
        "audience_permission",
        "destination_url",
        "learning_goal",
        "bid_basis",
        "bid_basis_reason",
        "spend_ceiling",
        "conversion_definition",
        "stop_conditions",
        "owner",
        "outcomes",
        "native_validation",
        "open_questions"
      ],
      "properties": {
        "objective": {
          "type": "string"
        },
        "audience": {
          "type": "string"
        },
        "audience_permission": {
          "type": "string"
        },
        "destination_url": {
          "type": "string"
        },
        "learning_goal": {
          "type": "string"
        },
        "bid_basis": {
          "type": "string"
        },
        "bid_basis_reason": {
          "type": "string"
        },
        "spend_ceiling": {
          "type": "object"
        },
        "conversion_definition": {
          "type": "string"
        },
        "stop_conditions": {
          "type": "array"
        },
        "owner": {
          "type": "string"
        },
        "outcomes": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "delivery",
            "click",
            "site_action",
            "crm_acceptance",
            "commercial_outcome"
          ],
          "properties": {
            "delivery": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "state",
                "value",
                "evidence_ref"
              ],
              "properties": {
                "state": {
                  "enum": [
                    "unknown",
                    "pending",
                    "verified",
                    "denied",
                    "not_applicable"
                  ]
                },
                "value": {
                  "type": [
                    "string",
                    "number",
                    "null"
                  ]
                },
                "evidence_ref": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            },
            "click": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "state",
                "value",
                "evidence_ref"
              ],
              "properties": {
                "state": {
                  "enum": [
                    "unknown",
                    "pending",
                    "verified",
                    "denied",
                    "not_applicable"
                  ]
                },
                "value": {
                  "type": [
                    "string",
                    "number",
                    "null"
                  ]
                },
                "evidence_ref": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            },
            "site_action": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "state",
                "value",
                "evidence_ref"
              ],
              "properties": {
                "state": {
                  "enum": [
                    "unknown",
                    "pending",
                    "verified",
                    "denied",
                    "not_applicable"
                  ]
                },
                "value": {
                  "type": [
                    "string",
                    "number",
                    "null"
                  ]
                },
                "evidence_ref": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            },
            "crm_acceptance": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "state",
                "value",
                "evidence_ref"
              ],
              "properties": {
                "state": {
                  "enum": [
                    "unknown",
                    "pending",
                    "verified",
                    "denied",
                    "not_applicable"
                  ]
                },
                "value": {
                  "type": [
                    "string",
                    "number",
                    "null"
                  ]
                },
                "evidence_ref": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            },
            "commercial_outcome": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "state",
                "value",
                "evidence_ref"
              ],
              "properties": {
                "state": {
                  "enum": [
                    "unknown",
                    "pending",
                    "verified",
                    "denied",
                    "not_applicable"
                  ]
                },
                "value": {
                  "type": [
                    "string",
                    "number",
                    "null"
                  ]
                },
                "evidence_ref": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            }
          }
        },
        "native_validation": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "state",
            "evidence_ref",
            "approved_revision",
            "approved_fingerprint"
          ],
          "properties": {
            "state": {
              "enum": [
                "unknown",
                "pending",
                "verified",
                "denied"
              ]
            },
            "evidence_ref": {
              "type": [
                "string",
                "null"
              ]
            },
            "approved_revision": {
              "type": [
                "integer",
                "null"
              ]
            },
            "approved_fingerprint": {
              "type": [
                "string",
                "null"
              ]
            }
          }
        },
        "open_questions": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "sources": {
      "type": "array",
      "minItems": 0,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "source_id",
          "reference",
          "captured_at",
          "sha256_or_locator",
          "permitted_use"
        ],
        "properties": {
          "source_id": {
            "type": "string",
            "minLength": 1
          },
          "reference": {
            "type": "string",
            "minLength": 1
          },
          "captured_at": {
            "type": "string",
            "minLength": 1
          },
          "sha256_or_locator": {
            "type": "string",
            "minLength": 1
          },
          "permitted_use": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "requests": {
      "type": "array",
      "minItems": 0,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "request_id",
          "field",
          "state",
          "next_action"
        ],
        "properties": {
          "request_id": {
            "type": "string",
            "minLength": 1
          },
          "field": {
            "type": "string",
            "minLength": 1
          },
          "state": {
            "enum": [
              "open",
              "resolved",
              "not_applicable"
            ]
          },
          "next_action": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "review": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "approved_revision",
        "reviewed_fingerprint",
        "shape",
        "semantic_evaluation",
        "readable_output",
        "source_traceability",
        "limit_checks",
        "final_verdict"
      ],
      "properties": {
        "approved_revision": {
          "type": [
            "integer",
            "null"
          ]
        },
        "reviewed_fingerprint": {
          "type": [
            "string",
            "null"
          ]
        },
        "shape": {
          "type": "boolean"
        },
        "semantic_evaluation": {
          "type": "boolean"
        },
        "readable_output": {
          "type": "boolean"
        },
        "source_traceability": {
          "type": "boolean"
        },
        "limit_checks": {
          "type": "boolean"
        },
        "final_verdict": {
          "type": "boolean"
        }
      }
    }
  }
}
