{
  "openapi": "3.1.0",
  "info": {
    "title": "Riskmark Merchant API",
    "version": "1.0.0-draft",
    "description": "Draft interface specification. API access and credential requests are pending."
  },
  "paths": {
    "/api/v1/stats": {
      "get": {
        "operationId": "getStats",
        "security": [],
        "responses": {
          "200": {
            "description": "Published statistics",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "code",
                    "data"
                  ],
                  "properties": {
                    "code": {
                      "const": 0
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "$ref": "#/components/schemas/Stats"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/records": {
      "get": {
        "operationId": "listPublicRecords",
        "security": [],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor returned on the previous page."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Page of published records",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "code",
                    "data"
                  ],
                  "properties": {
                    "code": {
                      "const": 0
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "items",
                        "nextCursor"
                      ],
                      "properties": {
                        "items": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/PublicRecord"
                          }
                        },
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/risk/check": {
      "post": {
        "operationId": "checkRisk",
        "description": "Exact email match for authorized merchants. Retry with the same request ID and input to obtain the same result without a second charge. Use server-side credentials and do not cache responses.",
        "security": [
          {
            "merchantBearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CheckRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Completed lookup",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "code",
                    "data"
                  ],
                  "properties": {
                    "code": {
                      "const": 0
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "$ref": "#/components/schemas/CheckResult"
                    }
                  }
                }
              }
            }
          },
          "402": {
            "description": "Insufficient credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid credentials",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Request ID conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "merchantBearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Stats": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "totalRecords",
          "weeklyAdded",
          "riskTypes"
        ],
        "properties": {
          "totalRecords": {
            "type": "integer",
            "minimum": 0
          },
          "weeklyAdded": {
            "type": "integer",
            "minimum": 0
          },
          "riskTypes": {
            "type": "integer",
            "minimum": 0
          }
        }
      },
      "PublicRecord": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "riskType",
          "status",
          "createdAt",
          "updatedAt"
        ],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^R-[0-9]{1,12}$"
          },
          "riskType": {
            "type": "string"
          },
          "status": {
            "const": "verified"
          },
          "createdAt": {
            "type": "string",
            "format": "date"
          },
          "updatedAt": {
            "type": "string",
            "format": "date"
          }
        }
      },
      "CheckRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "email",
          "requestId"
        ],
        "properties": {
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 254
          },
          "requestId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          }
        }
      },
      "CheckResult": {
        "oneOf": [
          {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "matched",
              "status",
              "remainingCredits"
            ],
            "properties": {
              "matched": {
                "const": false
              },
              "status": {
                "const": "no_record"
              },
              "remainingCredits": {
                "type": "integer",
                "minimum": 0
              }
            }
          },
          {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "matched",
              "riskTypes",
              "status",
              "recommendation",
              "updatedAt",
              "remainingCredits"
            ],
            "properties": {
              "matched": {
                "const": true
              },
              "riskTypes": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "status": {
                "type": "string",
                "enum": [
                  "verified",
                  "review_required"
                ]
              },
              "recommendation": {
                "const": "manual_review"
              },
              "updatedAt": {
                "type": "string",
                "format": "date"
              },
              "remainingCredits": {
                "type": "integer",
                "minimum": 0
              }
            }
          }
        ]
      },
      "Error": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "code",
          "message"
        ],
        "properties": {
          "code": {
            "type": "integer",
            "not": {
              "const": 0
            }
          },
          "message": {
            "type": "string"
          }
        }
      }
    }
  }
}
