{
  "openapi": "3.0.3",
  "info": {
    "title": "GlemO internal rail API candidate",
    "version": "0.1.0-draft",
    "description": "PROPOSED interface for engineering review. Not implemented, deployed, provider-approved or a statement that GlemO performs regulated settlement. All permissions are server-evaluated and deny by default."
  },
  "tags": [
    {
      "name": "Instruments"
    },
    {
      "name": "Offers"
    },
    {
      "name": "Demand"
    },
    {
      "name": "Quotes"
    },
    {
      "name": "Orders"
    }
  ],
  "security": [
    {
      "sessionCookie": []
    }
  ],
  "paths": {
    "/v1/instruments": {
      "post": {
        "tags": [
          "Instruments"
        ],
        "operationId": "createExternalInstrument",
        "summary": "Draft a mirror of an externally issued instrument",
        "description": "No issuance, custody or local token balance is created.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InstrumentInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Draft instrument",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResourceReceipt"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/v1/offers": {
      "get": {
        "tags": [
          "Offers"
        ],
        "operationId": "listPermittedOffers",
        "summary": "List only offers visible to the current actor",
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Permission-filtered offer page",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "items"
                  ],
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/OfferSummary"
                      }
                    },
                    "nextCursor": {
                      "type": "string",
                      "nullable": true
                    }
                  }
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          }
        }
      },
      "post": {
        "tags": [
          "Offers"
        ],
        "operationId": "createOfferDraft",
        "summary": "Draft an offer version for external supply",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OfferInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Draft created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResourceReceipt"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/v1/offers/{offerId}": {
      "get": {
        "tags": [
          "Offers"
        ],
        "operationId": "getPermittedOffer",
        "summary": "Read one authorized offer snapshot",
        "parameters": [
          {
            "$ref": "#/components/parameters/OfferId"
          }
        ],
        "responses": {
          "200": {
            "description": "Current offer snapshot",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OfferSummary"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/offers/{offerId}/submit": {
      "post": {
        "tags": [
          "Offers"
        ],
        "operationId": "submitOfferForReview",
        "summary": "Submit the current version; does not publish",
        "parameters": [
          {
            "$ref": "#/components/parameters/OfferId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "$ref": "#/components/parameters/IfMatch"
          }
        ],
        "responses": {
          "200": {
            "description": "Submitted for independent review",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResourceReceipt"
                }
              }
            }
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/v1/offers/{offerId}/decisions": {
      "post": {
        "tags": [
          "Offers"
        ],
        "operationId": "reviewOfferVersion",
        "summary": "Independent review of an exact offer version",
        "parameters": [
          {
            "$ref": "#/components/parameters/OfferId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "$ref": "#/components/parameters/IfMatch"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "decision",
                  "reasonCode",
                  "offerVersionId"
                ],
                "properties": {
                  "decision": {
                    "type": "string",
                    "enum": [
                      "approve",
                      "reject",
                      "suspend",
                      "publish"
                    ]
                  },
                  "reasonCode": {
                    "type": "string"
                  },
                  "offerVersionId": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Decision recorded under server-side reviewer and policy checks",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResourceReceipt"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/v1/mandates": {
      "post": {
        "tags": [
          "Demand"
        ],
        "operationId": "createBuyerMandate",
        "summary": "Record interest, not a funding commitment",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "category",
                  "ticketAmount",
                  "currency",
                  "consentVersion"
                ],
                "properties": {
                  "category": {
                    "type": "string"
                  },
                  "ticketAmount": {
                    "$ref": "#/components/schemas/DecimalString"
                  },
                  "currency": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 3
                  },
                  "consentVersion": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Mandate captured",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResourceReceipt"
                }
              }
            }
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/v1/indications": {
      "post": {
        "tags": [
          "Demand"
        ],
        "operationId": "createIndication",
        "summary": "Open a question, interest or counterproposal",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "mandateId",
                  "offerVersionId",
                  "kind"
                ],
                "properties": {
                  "mandateId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "offerVersionId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "kind": {
                    "type": "string",
                    "enum": [
                      "interest",
                      "question",
                      "counteroffer"
                    ]
                  },
                  "proposedTerms": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Indication recorded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResourceReceipt"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/v1/quotes": {
      "post": {
        "tags": [
          "Quotes"
        ],
        "operationId": "issueQuoteVersion",
        "summary": "Issue expiring terms to one eligible buyer",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "indicationId",
                  "terms",
                  "expiresAt"
                ],
                "properties": {
                  "indicationId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "terms": {
                    "type": "object",
                    "additionalProperties": true
                  },
                  "expiresAt": {
                    "type": "string",
                    "format": "date-time"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Quote version issued, not accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResourceReceipt"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/v1/quotes/{quoteId}/accept": {
      "post": {
        "tags": [
          "Quotes"
        ],
        "operationId": "acceptQuoteVersion",
        "summary": "Accept exactly one current quote version",
        "parameters": [
          {
            "$ref": "#/components/parameters/QuoteId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "$ref": "#/components/parameters/IfMatch"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "termsSha256"
                ],
                "properties": {
                  "termsSha256": {
                    "type": "string",
                    "minLength": 64,
                    "maxLength": 64
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Party acceptance recorded, not an order",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResourceReceipt"
                }
              }
            }
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/v1/orders": {
      "post": {
        "tags": [
          "Orders"
        ],
        "operationId": "convertAcceptedQuote",
        "summary": "Convert a fully accepted, permitted quote once",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "quoteVersionId"
                ],
                "properties": {
                  "quoteVersionId": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Pending order, not settlement",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResourceReceipt"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/orders/{orderId}/leg-evidence": {
      "post": {
        "tags": [
          "Orders"
        ],
        "operationId": "recordIndependentLegEvidence",
        "summary": "Internal adapter/reviewer only; reported is not confirmed",
        "security": [
          {
            "serviceBearer": []
          },
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/OrderId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LegEvidence"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Evidence event recorded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResourceReceipt"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/v1/orders/{orderId}/reconciliation": {
      "post": {
        "tags": [
          "Orders"
        ],
        "operationId": "reviewReconciliation",
        "summary": "Independent human-reviewed reconciliation",
        "parameters": [
          {
            "$ref": "#/components/parameters/OrderId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "$ref": "#/components/parameters/IfMatch"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "decision",
                  "reasonCode"
                ],
                "properties": {
                  "decision": {
                    "type": "string",
                    "enum": [
                      "approve",
                      "block"
                    ]
                  },
                  "reasonCode": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Decision recorded; approval requires both confirmed legs and no exception",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResourceReceipt"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/v1/orders/{orderId}/timeline": {
      "get": {
        "tags": [
          "Orders"
        ],
        "operationId": "getOrderTimeline",
        "summary": "Permission-filtered activity projection",
        "parameters": [
          {
            "$ref": "#/components/parameters/OrderId"
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sanitized events",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "items"
                  ],
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/TimelineEvent"
                      }
                    },
                    "nextCursor": {
                      "type": "string",
                      "nullable": true
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "sessionCookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "glemo_session",
        "description": "Candidate session mechanism; production identity choice open. CSRF protection required for browser writes."
      },
      "serviceBearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "Candidate internal service identity. Provider callbacks terminate at a separately authenticated adapter, not this user API."
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "minLength": 16,
          "maxLength": 128
        }
      },
      "IfMatch": {
        "name": "If-Match",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string"
        },
        "description": "Expected aggregate version/ETag."
      },
      "OfferId": {
        "name": "offerId",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "QuoteId": {
        "name": "quoteId",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "OrderId": {
        "name": "orderId",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      }
    },
    "schemas": {
      "DecimalString": {
        "type": "string",
        "pattern": "^[0-9]+(\\.[0-9]+)?$",
        "description": "Exact decimal string; never a binary floating-point amount."
      },
      "InstrumentInput": {
        "type": "object",
        "required": [
          "issuerName",
          "issuanceCountry",
          "sourceSystem",
          "externalRef",
          "rightsSummary",
          "quantityPrecision"
        ],
        "properties": {
          "issuerName": {
            "type": "string"
          },
          "issuanceCountry": {
            "type": "string",
            "minLength": 2,
            "maxLength": 2
          },
          "sourceSystem": {
            "type": "string"
          },
          "externalRef": {
            "type": "string"
          },
          "rightsSummary": {
            "type": "string"
          },
          "quantityPrecision": {
            "type": "integer",
            "minimum": 0,
            "maximum": 18
          }
        }
      },
      "OfferInput": {
        "type": "object",
        "required": [
          "instrumentId",
          "terms",
          "documentVersionId"
        ],
        "properties": {
          "instrumentId": {
            "type": "string",
            "format": "uuid"
          },
          "terms": {
            "type": "object",
            "additionalProperties": true
          },
          "documentVersionId": {
            "type": "string",
            "format": "uuid"
          }
        }
      },
      "OfferSummary": {
        "type": "object",
        "required": [
          "id",
          "version",
          "status",
          "issuerName",
          "issuanceCountry",
          "observedAt",
          "availabilityCaveat"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer"
          },
          "status": {
            "type": "string"
          },
          "issuerName": {
            "type": "string"
          },
          "issuanceCountry": {
            "type": "string"
          },
          "observedAt": {
            "type": "string",
            "format": "date-time"
          },
          "availabilityCaveat": {
            "type": "string"
          }
        }
      },
      "LegEvidence": {
        "type": "object",
        "required": [
          "leg",
          "status",
          "sourceRef",
          "amount",
          "unitOrCurrency",
          "occurredAt"
        ],
        "properties": {
          "leg": {
            "type": "string",
            "enum": [
              "cash",
              "asset"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "reported",
              "confirmed",
              "disputed",
              "reversed"
            ]
          },
          "sourceRef": {
            "type": "string"
          },
          "providerEventId": {
            "type": "string"
          },
          "amount": {
            "$ref": "#/components/schemas/DecimalString"
          },
          "unitOrCurrency": {
            "type": "string"
          },
          "evidenceDocumentId": {
            "type": "string",
            "format": "uuid"
          },
          "occurredAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ResourceReceipt": {
        "type": "object",
        "required": [
          "id",
          "version",
          "status",
          "createdAt",
          "updatedAt"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer"
          },
          "status": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "policyDecisionId": {
            "type": "string",
            "format": "uuid"
          }
        }
      },
      "TimelineEvent": {
        "type": "object",
        "required": [
          "eventId",
          "eventType",
          "occurredAt",
          "actorType"
        ],
        "properties": {
          "eventId": {
            "type": "string",
            "format": "uuid"
          },
          "eventType": {
            "type": "string"
          },
          "occurredAt": {
            "type": "string",
            "format": "date-time"
          },
          "actorType": {
            "type": "string"
          },
          "summary": {
            "type": "string"
          }
        }
      },
      "ApiError": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "correlationId",
              "retryable"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "correlationId": {
                "type": "string"
              },
              "retryable": {
                "type": "boolean"
              }
            }
          }
        }
      }
    },
    "responses": {
      "Denied": {
        "description": "Server policy denied",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "NotFound": {
        "description": "Object unavailable or hidden from current actor",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "Conflict": {
        "description": "Version or idempotency conflict",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "Invalid": {
        "description": "Validation, policy or evidence requirement failed",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "Unavailable": {
        "description": "Required external service unavailable",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      }
    }
  }
}
