{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/dockflow-com/json-schema/dockflow-com-downstream-tradeflow-schema.json",
  "title": "DownstreamTradeflow",
  "description": "A tradeflow to create, or to update when its tradeflow_reference already exists.",
  "x-generated": "2026-12-02",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/dockflow-com-openapi.json#/components/schemas/DownstreamTradeflow",
  "type": "object",
  "properties": {
    "tradeflow_reference": {
      "type": "string",
      "description": "Your unique reference for the tradeflow, for example a purchase order number."
    },
    "container_reference": {
      "description": "Container numbers (ISO 6346), as a string, an array of strings, or objects with custom properties.",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "array",
          "items": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "object",
                "properties": {
                  "reference": {
                    "type": "string"
                  },
                  "custom_properties": {
                    "type": "object",
                    "description": "Free-form key-value pairs stored on the container."
                  }
                },
                "required": [
                  "reference"
                ]
              }
            ]
          }
        }
      ]
    },
    "container_references_complete": {
      "type": "boolean",
      "description": "When true, containers not listed are removed from the tradeflow. When omitted, the list is merged."
    },
    "bill_of_lading_reference": {
      "description": "Bill of lading number, with the carrier prefix, as a string or an array.",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      ]
    },
    "bill_of_lading_references_complete": {
      "type": "boolean",
      "description": "When true, bills of lading not listed are removed."
    },
    "booking_reference": {
      "description": "Booking number, as a string or an array.",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      ]
    },
    "booking_references_complete": {
      "type": "boolean",
      "description": "When true, bookings not listed are removed."
    },
    "active": {
      "type": "boolean",
      "description": "Set to false to deactivate the tradeflow."
    },
    "carrier_name": {
      "type": "string"
    },
    "carrier_scac": {
      "type": "string",
      "description": "Carrier SCAC. A hint for which carrier to ask first; other carriers are still tried."
    },
    "customer_name": {
      "type": "string",
      "description": "Adds one partner with the role customer."
    },
    "customer_reference": {
      "type": "string"
    },
    "partners": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "role": {
            "type": "string"
          },
          "reference": {
            "type": "string",
            "description": "The partner's own reference for this tradeflow."
          },
          "lead_contact": {
            "type": "string",
            "description": "Email or full name of an existing user at the partner."
          }
        },
        "required": [
          "name"
        ]
      }
    },
    "partners_complete": {
      "type": "boolean",
      "description": "When true, partners not listed are removed."
    },
    "team_name": {
      "type": "string",
      "description": "Name of an existing team. Ignored when no team matches."
    },
    "lead_contact": {
      "type": "string",
      "description": "Email or full name of an existing user in your organisation. Ignored when no user matches."
    },
    "port_of_loading": {
      "type": "string",
      "description": "5-character UN/LOCODE."
    },
    "port_of_discharge": {
      "type": "string",
      "description": "5-character UN/LOCODE."
    },
    "estimated_time_of_departure": {
      "type": "string",
      "format": "date-time"
    },
    "actual_time_of_departure": {
      "type": "string",
      "format": "date-time"
    },
    "estimated_time_of_arrival": {
      "type": "string",
      "format": "date-time"
    },
    "actual_time_of_arrival": {
      "type": "string",
      "format": "date-time"
    },
    "vessel": {
      "type": "string"
    },
    "incoterms": {
      "type": "string"
    },
    "references": {
      "type": "object",
      "properties": {
        "house_bill_of_lading": {
          "type": "string"
        },
        "delivery_location": {
          "type": "string"
        },
        "delivery_event_date": {
          "type": "string"
        }
      }
    },
    "events": {
      "type": "array",
      "description": "Your own events on the tradeflow.",
      "items": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string"
          },
          "container_reference": {
            "type": "string"
          },
          "location_name": {
            "type": "string",
            "description": "5-character UN/LOCODE; any other value leaves the event without a location."
          },
          "event_date": {
            "type": "string",
            "format": "date-time"
          },
          "actual": {
            "type": "boolean",
            "description": "Whether the event already happened (true) or is planned (false)."
          }
        },
        "required": [
          "message",
          "event_date"
        ]
      }
    },
    "free_time_overrides": {
      "type": "array",
      "description": "Free-time overrides, upserted per scope. Unlisted scopes are untouched.",
      "items": {
        "type": "object",
        "properties": {
          "dwell_type": {
            "type": "string",
            "enum": [
              "equipment_free_time_in_port",
              "equipment_free_time_out_of_port",
              "equipment_free_time_combined",
              "storage_free_time",
              "electricity_free_time"
            ]
          },
          "free_days": {
            "type": "integer",
            "description": "Required unless cancelled is true."
          },
          "container_reference": {
            "type": "string",
            "description": "Scopes the override to one container. Absent means tradeflow-wide."
          },
          "cancelled": {
            "type": "boolean"
          }
        },
        "required": [
          "dwell_type"
        ]
      }
    },
    "custom_references": {
      "type": "object",
      "description": "Flat key-value pairs you define. Values are stored as text; null or an empty string removes the key."
    },
    "mock_tracking": {
      "type": "object",
      "description": "UAT only: generates a synthetic journey. Ignored in production.",
      "properties": {
        "scenario": {
          "type": "string"
        }
      }
    }
  },
  "required": [
    "tradeflow_reference"
  ]
}