{
  "openapi": "3.1.0",
  "info": {
    "title": "Quote in Seconds API",
    "version": "1.0.0-prototype",
    "description": "API-first quoting for SME and Individual medical business. Simulated — no external system is called. Demo data and illustrative rates."
  },
  "servers": [
    {
      "url": "https://cigna-quote-in-seconds.aqionlabs.workers.dev/api/v1"
    }
  ],
  "tags": [
    {
      "name": "Census"
    },
    {
      "name": "Rating"
    },
    {
      "name": "Quotes"
    },
    {
      "name": "Documents"
    },
    {
      "name": "Integrations"
    },
    {
      "name": "Webhooks"
    },
    {
      "name": "Reports"
    },
    {
      "name": "Compliance"
    }
  ],
  "components": {
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        },
        "required": [
          "error"
        ]
      },
      "Options": {
        "type": "object",
        "properties": {
          "network": {
            "enum": [
              "essential",
              "standard",
              "premium",
              "global"
            ]
          },
          "copay": {
            "enum": [
              0,
              10,
              20,
              30
            ]
          },
          "maternity": {
            "type": "boolean"
          },
          "dependants": {
            "type": "boolean"
          },
          "annualLimit": {
            "enum": [
              "150k",
              "500k",
              "1m",
              "5m"
            ]
          },
          "area": {
            "enum": [
              "uae",
              "mena",
              "ww_ex_us",
              "ww"
            ]
          }
        },
        "required": []
      },
      "Member": {
        "type": "object",
        "properties": {
          "line": {
            "type": "integer"
          },
          "relation": {
            "enum": [
              "Employee",
              "Spouse",
              "Child"
            ]
          },
          "gender": {
            "enum": [
              "M",
              "F"
            ]
          },
          "age": {
            "type": "integer"
          },
          "emirate": {
            "type": "string"
          },
          "eligibility": {
            "type": "string"
          },
          "medical": {
            "type": "boolean"
          }
        },
        "required": []
      },
      "Applicant": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "age": {
            "type": "integer"
          },
          "dob": {
            "type": "string",
            "format": "date"
          },
          "gender": {
            "enum": [
              "M",
              "F"
            ]
          },
          "emirate": {
            "type": "string"
          },
          "salary": {
            "type": "number"
          },
          "medical": {
            "type": "boolean"
          },
          "dependants": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Member"
            }
          }
        },
        "required": [
          "gender"
        ]
      },
      "QuoteRequest": {
        "type": "object",
        "properties": {
          "segment": {
            "enum": [
              "SME",
              "Individual"
            ]
          },
          "company": {
            "type": "string"
          },
          "members": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Member"
            }
          },
          "applicant": {
            "$ref": "#/components/schemas/Applicant"
          },
          "options": {
            "$ref": "#/components/schemas/Options"
          }
        },
        "required": [
          "segment"
        ]
      },
      "Quote": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "segment": {
            "type": "string"
          },
          "status": {
            "enum": [
              "Quoted",
              "Referred",
              "Bound"
            ]
          },
          "current": {
            "type": "object"
          },
          "versions": {
            "type": "array"
          }
        },
        "required": []
      },
      "Event": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "type": {
            "enum": [
              "census.cleaned",
              "quote.created",
              "quote.versioned",
              "quote.referred",
              "quote.approved",
              "quote.midterm",
              "quote.renewal",
              "quote.bound",
              "document.classified",
              "payment.collected (later phase)",
              "policy.issued (later phase)"
            ]
          },
          "idempotencyKey": {
            "type": "string"
          },
          "at": {
            "type": "string"
          },
          "data": {
            "type": "object"
          }
        },
        "required": []
      }
    }
  },
  "paths": {
    "/census": {
      "post": {
        "summary": "Clean & map a census (CSV text, rows, or multipart file)",
        "tags": [
          "Census"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "csv": {
                    "type": "string"
                  },
                  "rows": {
                    "type": "array"
                  },
                  "columnMap": {
                    "type": "object"
                  }
                },
                "required": []
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/rate": {
      "post": {
        "summary": "Rate SME group or Individual — no quote created",
        "tags": [
          "Rating"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "segment": {
                    "enum": [
                      "SME",
                      "Individual"
                    ]
                  },
                  "members": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/Member"
                    }
                  },
                  "applicant": {
                    "$ref": "#/components/schemas/Applicant"
                  },
                  "options": {
                    "$ref": "#/components/schemas/Options"
                  }
                },
                "required": []
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/quotes": {
      "post": {
        "summary": "Create quote (SME or Individual)",
        "tags": [
          "Quotes"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QuoteRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 80
            },
            "description": "Replays return the original response (24 h) with header Idempotent-Replay: true."
          }
        ]
      }
    },
    "/quotes/{id}": {
      "get": {
        "summary": "Fetch quote",
        "tags": [
          "Quotes"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Quote",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Quote"
                }
              }
            }
          },
          "404": {
            "description": "Not found / expired"
          }
        }
      }
    },
    "/quotes/{id}/versions": {
      "post": {
        "summary": "Re-rate and add a version",
        "tags": [
          "Quotes"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "members": {
                    "type": "array"
                  },
                  "options": {
                    "$ref": "#/components/schemas/Options"
                  },
                  "reason": {
                    "type": "string"
                  }
                },
                "required": []
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 80
            },
            "description": "Replays return the original response (24 h) with header Idempotent-Replay: true."
          }
        ]
      }
    },
    "/quotes/{id}/midterm": {
      "post": {
        "summary": "Mid-term endorsement (pro-rata)",
        "tags": [
          "Quotes"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "livesDelta": {
                    "type": "integer"
                  },
                  "daysRemaining": {
                    "type": "integer"
                  }
                },
                "required": []
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/quotes/{id}/renewal": {
      "post": {
        "summary": "Renewal terms",
        "tags": [
          "Quotes"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "trend": {
                    "type": "number"
                  },
                  "lossRatio": {
                    "type": "number"
                  }
                },
                "required": []
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/documents": {
      "post": {
        "summary": "Bulk upload & classify documents (multipart, field 'files'); content processed in memory, not stored",
        "tags": [
          "Documents"
        ],
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "files": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "binary"
                    }
                  },
                  "quoteId": {
                    "type": "string"
                  }
                },
                "required": []
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Per-file classification"
          }
        }
      }
    },
    "/integrations": {
      "get": {
        "summary": "Adapters and Salesforce field mapping",
        "tags": [
          "Integrations"
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/integrations/{target}/preview": {
      "post": {
        "summary": "Preview the outbound payload for salesforce | rating | pas | payment | issuance (simulated)",
        "tags": [
          "Integrations"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "quote": {
                    "$ref": "#/components/schemas/Quote"
                  },
                  "members": {
                    "type": "array"
                  }
                },
                "required": []
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "target",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "salesforce",
                "rating",
                "pas",
                "payment",
                "issuance"
              ]
            }
          }
        ]
      }
    },
    "/webhooks": {
      "get": {
        "summary": "Event types emitted by the outbox",
        "tags": [
          "Webhooks"
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/webhooks/test": {
      "post": {
        "summary": "Build a signed sample webhook delivery (HMAC-style demo signature)",
        "tags": [
          "Webhooks"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string"
                  }
                },
                "required": []
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/reports/pipeline": {
      "get": {
        "summary": "Pipeline, conversion, turnaround and underwriting exceptions (simulated history)",
        "tags": [
          "Reports"
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/compliance/controls": {
      "get": {
        "summary": "Residency options and regulatory design controls (designed for — not certified)",
        "tags": [
          "Compliance"
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/payments": {
      "post": {
        "summary": "Later phase — payment intent (returns 501 with contract)",
        "tags": [
          "Integrations"
        ],
        "responses": {
          "501": {
            "description": "Later phase"
          }
        }
      }
    },
    "/policies": {
      "post": {
        "summary": "Later phase — issuance (returns 501 with contract)",
        "tags": [
          "Integrations"
        ],
        "responses": {
          "501": {
            "description": "Later phase"
          }
        }
      }
    }
  }
}