{
  "$defs": {
    "ChangeRequestStatus": {
      "description": "Lifecycle status of a change request.",
      "enum": [
        "pending",
        "validating",
        "pending_approval",
        "approved",
        "rejected",
        "applied",
        "failed"
      ],
      "title": "ChangeRequestStatus",
      "type": "string"
    },
    "ChangeSeverity": {
      "description": "How significant the change is \u2014 determines approval requirements.",
      "enum": [
        "minor",
        "material",
        "critical"
      ],
      "title": "ChangeSeverity",
      "type": "string"
    },
    "ChangeType": {
      "description": "Category of change being requested.\n\n``makegood`` implements flagged decision FD-6: makegoods are a typed\nChangeRequest subtype, not a separate primitive.",
      "enum": [
        "flight_dates",
        "impressions",
        "pricing",
        "creative",
        "targeting",
        "cancellation",
        "makegood",
        "other"
      ],
      "title": "ChangeType",
      "type": "string"
    },
    "FieldDiff": {
      "description": "A single field-level change.",
      "properties": {
        "field": {
          "title": "Field",
          "type": "string"
        },
        "new_value": {
          "default": null,
          "title": "New Value"
        },
        "old_value": {
          "default": null,
          "title": "Old Value"
        }
      },
      "required": [
        "field"
      ],
      "title": "FieldDiff",
      "type": "object"
    },
    "MakegoodDetails": {
      "description": "Makegood payload for a ChangeRequest of type ``makegood`` (FD-6).\n\nSent when delivery falls short of the guaranteed level; the seller\nresponds with replacement inventory. Carries the compensation terms:\nwhat is owed (``shortfall_grps`` for linear TV, ``owed_impressions``\nfor digital), the proposed replacement flight, and the makegood\n``status``. The human-readable reason lives on the enclosing\n:class:`ChangeRequest.reason` (not duplicated here). GRP = gross rating\npoint.",
      "properties": {
        "notes": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Notes"
        },
        "original_daypart": {
          "description": "Daypart where the underdelivery occurred.",
          "title": "Original Daypart",
          "type": "string"
        },
        "owed_impressions": {
          "anyOf": [
            {
              "minimum": 0,
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Impressions owed for a digital makegood; None for a pure-GRP makegood.",
          "title": "Owed Impressions"
        },
        "preferred_dayparts": {
          "anyOf": [
            {
              "items": {
                "type": "string"
              },
              "type": "array"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Buyer's preferred dayparts for replacement inventory.",
          "title": "Preferred Dayparts"
        },
        "replacement_flight_end": {
          "anyOf": [
            {
              "format": "date",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Proposed end of the replacement flight.",
          "title": "Replacement Flight End"
        },
        "replacement_flight_start": {
          "anyOf": [
            {
              "format": "date",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Proposed start of the replacement flight.",
          "title": "Replacement Flight Start"
        },
        "shortfall_grps": {
          "description": "GRP shortfall owed that needs to be made up (linear TV).",
          "title": "Shortfall Grps",
          "type": "number"
        },
        "status": {
          "$ref": "#/$defs/MakegoodStatus",
          "default": "proposed",
          "description": "Compensation status of the makegood."
        },
        "target_demo": {
          "description": "Target demographic for makegood inventory.",
          "title": "Target Demo",
          "type": "string"
        }
      },
      "required": [
        "shortfall_grps",
        "original_daypart",
        "target_demo"
      ],
      "title": "MakegoodDetails",
      "type": "object"
    },
    "MakegoodStatus": {
      "description": "Compensation status of a makegood (EP-10.2).",
      "enum": [
        "proposed",
        "accepted",
        "scheduled",
        "delivered",
        "rejected"
      ],
      "title": "MakegoodStatus",
      "type": "string"
    }
  },
  "description": "A request to modify an existing order or deal post-booking.\n\nID minting: ``change_request_id`` is seller-issued (the buyer submits\nthe request; the seller assigns the identifier and owns its lifecycle).",
  "properties": {
    "applied_at": {
      "anyOf": [
        {
          "format": "date-time",
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Applied At"
    },
    "applied_by": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Applied By"
    },
    "approved_at": {
      "anyOf": [
        {
          "format": "date-time",
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Approved At"
    },
    "approved_by": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Approved By"
    },
    "availability_check": {
      "anyOf": [
        {
          "additionalProperties": true,
          "type": "object"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Availability Check"
    },
    "change_request_id": {
      "description": "Seller-issued change request identifier.",
      "title": "Change Request Id",
      "type": "string"
    },
    "change_type": {
      "$ref": "#/$defs/ChangeType"
    },
    "deal_id": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Deal being modified; at least one of order_id/deal_id.",
      "title": "Deal Id"
    },
    "diffs": {
      "items": {
        "$ref": "#/$defs/FieldDiff"
      },
      "title": "Diffs",
      "type": "array"
    },
    "makegood": {
      "anyOf": [
        {
          "$ref": "#/$defs/MakegoodDetails"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Required when change_type == 'makegood' (FD-6)."
    },
    "order_id": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Order being modified; at least one of order_id/deal_id.",
      "title": "Order Id"
    },
    "pricing_impact": {
      "anyOf": [
        {
          "additionalProperties": true,
          "type": "object"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Pricing Impact"
    },
    "proposed_values": {
      "additionalProperties": true,
      "title": "Proposed Values",
      "type": "object"
    },
    "reason": {
      "default": "",
      "title": "Reason",
      "type": "string"
    },
    "rejection_reason": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Rejection Reason"
    },
    "requested_at": {
      "format": "date-time",
      "title": "Requested At",
      "type": "string"
    },
    "requested_by": {
      "default": "system",
      "description": "Actor id: 'system', 'human:<id>', or 'agent:<id>'.",
      "title": "Requested By",
      "type": "string"
    },
    "severity": {
      "$ref": "#/$defs/ChangeSeverity",
      "default": "material"
    },
    "status": {
      "$ref": "#/$defs/ChangeRequestStatus",
      "default": "pending"
    },
    "validation_errors": {
      "items": {
        "type": "string"
      },
      "title": "Validation Errors",
      "type": "array"
    }
  },
  "required": [
    "change_request_id",
    "change_type"
  ],
  "title": "ChangeRequest",
  "type": "object"
}
