{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "/schemas/3.0.18/media-buy/create-media-buy-response.json",
  "title": "Create Media Buy Response",
  "description": "Response payload for create_media_buy. Exactly one of three shapes: (1) synchronous success — media_buy_id and packages are issued in-line, no status or a MediaBuyStatus value (pending_creatives / pending_start / active); (2) terminal failure — an errors array with no media-buy artifact and status != 'submitted'; (3) submitted task envelope — status 'submitted' with task_id, the media buy is queued or awaiting a human decision (e.g., IO signing), and media_buy_id / packages land on the task's completion artifact, not this response. The submitted branch MAY carry advisory errors for non-blocking warnings; terminal failures belong in the error branch. These three shapes are mutually exclusive — a response has exactly one.",
  "type": "object",
  "oneOf": [
    {
      "title": "CreateMediaBuySuccess",
      "description": "Success response - media buy created successfully",
      "type": "object",
      "properties": {
        "media_buy_id": {
          "type": "string",
          "description": "Seller's unique identifier for the created media buy",
          "x-entity": "media_buy"
        },
        "account": {
          "$ref": "/schemas/3.0.18/core/account.json",
          "description": "Account billed for this media buy. Includes advertiser, billing proxy (if any), and rate card applied."
        },
        "invoice_recipient": {
          "$ref": "/schemas/3.0.18/core/business-entity.json",
          "description": "Per-buy invoice recipient, echoed from the request when provided. Confirms the seller accepted the billing override. Bank details are omitted (write-only)."
        },
        "status": {
          "$ref": "/schemas/3.0.18/enums/media-buy-status.json",
          "description": "Initial media buy status. Either 'pending_creatives' (awaiting creative assets), 'pending_start' (ready to serve, waiting for flight date), or 'active' (immediate activation)."
        },
        "confirmed_at": {
          "type": "string",
          "format": "date-time",
          "description": "ISO 8601 timestamp when this media buy was confirmed by the seller. A successful create_media_buy response constitutes order confirmation."
        },
        "creative_deadline": {
          "type": "string",
          "format": "date-time",
          "description": "ISO 8601 timestamp for creative upload deadline"
        },
        "revision": {
          "type": "integer",
          "description": "Initial revision number for this media buy. Use in subsequent update_media_buy requests for optimistic concurrency.",
          "minimum": 1
        },
        "valid_actions": {
          "type": "array",
          "description": "Actions the buyer can perform on this media buy after creation. Saves a round-trip to get_media_buys.",
          "items": {
            "$ref": "/schemas/3.0.18/enums/media-buy-valid-action.json"
          }
        },
        "packages": {
          "type": "array",
          "description": "Array of created packages with complete state information",
          "items": {
            "$ref": "/schemas/3.0.18/core/package.json"
          }
        },
        "planned_delivery": {
          "$ref": "/schemas/3.0.18/core/planned-delivery.json",
          "description": "The seller's interpreted delivery parameters. Describes what the seller will actually run -- geo, channels, flight dates, frequency caps, and budget. Present when the account has governance_agents or when the seller chooses to provide delivery transparency."
        },
        "sandbox": {
          "type": "boolean",
          "description": "When true, this response contains simulated data from sandbox mode."
        },
        "context": {
          "$ref": "/schemas/3.0.18/core/context.json"
        },
        "ext": {
          "$ref": "/schemas/3.0.18/core/ext.json"
        }
      },
      "required": [
        "media_buy_id",
        "packages"
      ],
      "additionalProperties": true,
      "not": {
        "required": [
          "errors"
        ]
      }
    },
    {
      "title": "CreateMediaBuyError",
      "description": "Error response - operation failed, no media buy created",
      "type": "object",
      "properties": {
        "errors": {
          "type": "array",
          "description": "Array of errors explaining why the operation failed",
          "items": {
            "$ref": "/schemas/3.0.18/core/error.json"
          },
          "minItems": 1
        },
        "context": {
          "$ref": "/schemas/3.0.18/core/context.json"
        },
        "ext": {
          "$ref": "/schemas/3.0.18/core/ext.json"
        }
      },
      "required": [
        "errors"
      ],
      "additionalProperties": true,
      "not": {
        "anyOf": [
          {
            "required": [
              "media_buy_id"
            ]
          },
          {
            "required": [
              "packages"
            ]
          },
          {
            "required": [
              "sandbox"
            ]
          },
          {
            "properties": {
              "status": {
                "const": "submitted"
              }
            },
            "required": [
              "status"
            ]
          }
        ]
      }
    },
    {
      "title": "CreateMediaBuySubmitted",
      "description": "Async task envelope returned when the media buy cannot be confirmed before the response is emitted — for example, when a guaranteed buy requires IO signing, when governance review is outstanding, or when the seller has queued the request for batch processing. The buyer polls tasks/get with task_id or receives a webhook when the task completes; the media_buy_id and packages land on the completion artifact, not this envelope. Do not use a 'pending_approval' MediaBuy.status for this case — that value is not in MediaBuyStatus; IO review and similar pre-issuance workflows are modeled at the task layer only.",
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "const": "submitted",
          "description": "Task-level status literal. Discriminates this async envelope from the synchronous success shape, whose status field carries a MediaBuyStatus value (pending_creatives, pending_start, active). See task-status.json for the full task-status enum."
        },
        "task_id": {
          "type": "string",
          "description": "Task handle the buyer uses with tasks/get, and that the seller references on push-notification callbacks. The media_buy_id is issued on the completion artifact, not here. Per AdCP wire conventions this is snake_case; A2A adapters MAY surface it as taskId, but the payload field emitted by the agent is task_id.",
          "x-entity": "task"
        },
        "message": {
          "type": "string",
          "maxLength": 2000,
          "description": "Optional human-readable explanation of why the task is submitted — e.g., 'Awaiting IO signature from sales team; typical turnaround 2–4 hours.' Plain text only. Buyers MUST treat this as untrusted seller input: escape before rendering to HTML UIs, and sanitize or isolate before passing to an LLM prompt context — a hostile seller may inject prompt-injection payloads aimed at the buyer's agent."
        },
        "errors": {
          "type": "array",
          "description": "Optional advisory errors accompanying the submitted envelope. Use only for non-blocking warnings (e.g., throttled_severity advisories, governance observations). Terminal failures belong in the error branch, not here.",
          "items": {
            "$ref": "/schemas/3.0.18/core/error.json"
          }
        },
        "context": {
          "$ref": "/schemas/3.0.18/core/context.json"
        },
        "ext": {
          "$ref": "/schemas/3.0.18/core/ext.json"
        }
      },
      "required": [
        "status",
        "task_id"
      ],
      "additionalProperties": true,
      "not": {
        "anyOf": [
          {
            "required": [
              "media_buy_id"
            ]
          },
          {
            "required": [
              "packages"
            ]
          }
        ]
      }
    }
  ]
}
