{
  "openapi": "3.0.3",
  "info": {
    "title": "Xuanji Fortune API",
    "version": "0.3.0",
    "description": "Public website pricing and status, Point Card balance, and conditional paid readings. Check public_reading_enabled before paid reading integration."
  },
  "servers": [{ "url": "https://easylifehub.net/wp-json/xuanji/v1" }],
  "paths": {
    "/service": {
      "get": {
        "operationId": "get_xuanji_api_status",
        "summary": "Check the API version and third-party reading availability",
        "responses": {
          "200": {
            "description": "Service status",
            "content": { "application/json": { "schema": {
              "type": "object",
              "required": ["name", "api_version", "public_reading_enabled"],
              "properties": {
                "name": { "type": "string", "example": "玄機命盤" },
                "api_version": { "type": "string", "enum": ["v1"] },
                "public_reading_enabled": { "type": "boolean", "example": false },
                "guide_url": { "type": "string", "format": "uri" },
                "reading_website_url": { "type": "string", "format": "uri" }
              }
            } } }
          }
        }
      }
    },
    "/paid-reading/status": {
      "get": {
        "operationId": "get_xuanji_service_catalog",
        "summary": "Check for an active public offer on the website",
        "responses": {
          "200": {
            "description": "Offer details, or offer: null when no public price is available",
            "content": { "application/json": { "schema": {
              "type": "object",
              "required": ["offer"],
              "properties": {
                "offer": {
                  "type": "object",
                  "nullable": true,
                  "required": ["currency", "amount", "expires"],
                  "properties": {
                    "currency": { "type": "string", "enum": ["TWD"] },
                    "amount": { "type": "integer", "minimum": 1, "description": "Amount in whole New Taiwan Dollars" },
                    "expires": { "type": "integer", "minimum": 1, "nullable": true, "description": "Campaign end as Unix time in seconds. Null for regular pricing." },
                    "discount_percent": { "type": "integer", "enum": [20], "description": "Present when the verified campaign is active." }
                  }
                }
              }
            } } }
          }
        }
      }
    },
    "/points/balance": {
      "post": {
        "operationId": "get_xuanji_point_balance",
        "summary": "Read the balance of a card you hold without spending points",
        "requestBody": { "required": true, "content": { "application/json": { "schema": {
          "type": "object",
          "required": ["card_token"],
          "properties": { "card_token": { "type": "string", "format": "password", "writeOnly": true } }
        } } } },
        "responses": {
          "200": {
            "description": "Balance for an active card",
            "content": { "application/json": { "schema": {
              "type": "object",
              "required": ["ok", "current_points", "status"],
              "properties": {
                "ok": { "type": "boolean", "enum": [true] },
                "display_code": { "type": "string" },
                "current_points": { "type": "integer", "minimum": 0 },
                "status": { "type": "string", "enum": ["ACTIVE"] }
              }
            } } }
          },
          "404": {
            "description": "The card is invalid or disabled",
            "content": { "application/json": { "schema": {
              "type": "object",
              "required": ["ok", "code"],
              "properties": {
                "ok": { "type": "boolean", "enum": [false] },
                "code": { "type": "string", "enum": ["invalid_card", "disabled_card"] }
              }
            } } }
          }
        }
      }
    },
    "/point-readings/quote": {
      "post": {
        "operationId": "get_xuanji_reading_quote",
        "summary": "Get the server-approved point quote",
        "description": "For one card use Authorization: Bearer <CARD_TOKEN>. For multiple cards use the ordered point_cards array instead. These endpoints are enabled only after production approval.",
        "security": [
          {
            "PointCard": []
          },
          {}
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._-]{8,96}$"
            },
            "in": "header"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PointReadingInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReadingQuote"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Missing or invalid card"
          },
          "402": {
            "description": "Insufficient points"
          },
          "404": {
            "description": "Reading not found or endpoint unavailable"
          },
          "409": {
            "description": "Quote or idempotency conflict"
          },
          "413": {
            "description": "Request too large"
          },
          "422": {
            "description": "Chart could not be constructed"
          },
          "429": {
            "description": "Request rate or provider budget exceeded"
          },
          "503": {
            "description": "Storage or worker temporarily unavailable"
          }
        }
      }
    },
    "/point-readings/submit": {
      "post": {
        "operationId": "submit_xuanji_reading",
        "summary": "Accept the quote and request a paid reading",
        "description": "For one card use Authorization: Bearer <CARD_TOKEN>. For multiple cards use the ordered point_cards array instead. These endpoints are enabled only after production approval.",
        "security": [
          {
            "PointCard": []
          },
          {}
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._-]{8,96}$"
            },
            "in": "header"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/PointReadingInput"
                  },
                  {
                    "type": "object",
                    "required": [
                      "quote",
                      "confirm_charge"
                    ],
                    "properties": {
                      "quote": {
                        "$ref": "#/components/schemas/ReadingQuote"
                      },
                      "confirm_charge": {
                        "type": "boolean",
                        "enum": [
                          true
                        ]
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReadingResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Missing or invalid card"
          },
          "402": {
            "description": "Insufficient points"
          },
          "404": {
            "description": "Reading not found or endpoint unavailable"
          },
          "409": {
            "description": "Quote or idempotency conflict"
          },
          "413": {
            "description": "Request too large"
          },
          "422": {
            "description": "Chart could not be constructed"
          },
          "429": {
            "description": "Request rate or provider budget exceeded"
          },
          "503": {
            "description": "Storage or worker temporarily unavailable"
          },
          "202": {
            "description": "Reading in progress",
            "headers": {"Retry-After": {"description": "Seconds before polling", "schema": {"type": "integer","minimum": 1}}},
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReadingResult"
                }
              }
            }
          }
        }
      }
    },
    "/point-readings/result": {
      "post": {
        "operationId": "get_xuanji_reading",
        "summary": "Retrieve status or authorized private report",
        "description": "For one card use Authorization: Bearer <CARD_TOKEN>. For multiple cards use the ordered point_cards array instead. These endpoints are enabled only after production approval.",
        "security": [
          {
            "PointCard": []
          },
          {}
        ],
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "operation_id"
                ],
                "properties": {
                  "operation_id": {
                    "type": "string",
                    "pattern": "^pcr_[0-9a-f]{24}$"
                  },
                  "point_cards": {
                    "type": "array",
                    "maxItems": 16,
                    "minItems": 1,
                    "items": {
                      "type": "string",
                      "format": "password",
                      "writeOnly": true
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReadingResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Missing or invalid card"
          },
          "402": {
            "description": "Insufficient points"
          },
          "404": {
            "description": "Reading not found or endpoint unavailable"
          },
          "409": {
            "description": "Quote or idempotency conflict"
          },
          "413": {
            "description": "Request too large"
          },
          "422": {
            "description": "Chart could not be constructed"
          },
          "429": {
            "description": "Request rate or provider budget exceeded"
          },
          "503": {
            "description": "Storage or worker temporarily unavailable"
          },
          "202": {
            "description": "Reading in progress",
            "headers": {"Retry-After": {"description": "Seconds before polling", "schema": {"type": "integer","minimum": 1}}},
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReadingResult"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "PointCard": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "PointReadingInput": {
        "type": "object",
        "required": [
          "birth",
          "question"
        ],
        "properties": {
          "question": {
            "type": "string",
            "minLength": 1,
            "maxLength": 50
          },
          "birth": {
            "type": "object",
            "required": [
              "birth_date",
              "birth_time"
            ],
            "properties": {
              "subject_type": {
                "type": "string",
                "enum": [
                  "person",
                  "company"
                ]
              },
              "name": {
                "type": "string",
                "maxLength": 50
              },
              "gender": {
                "type": "string",
                "enum": [
                  "男性",
                  "女性"
                ]
              },
              "birth_date": {
                "type": "string",
                "format": "date"
              },
              "birth_time": {
                "type": "string",
                "example": "12:00"
              }
            }
          },
          "point_cards": {
            "type": "array",
            "maxItems": 16,
            "minItems": 1,
            "items": {
              "type": "string",
              "format": "password",
              "writeOnly": true
            }
          }
        }
      },
      "ReadingQuote": {
        "type": "object",
        "required": [
          "points",
          "expires",
          "proof"
        ],
        "properties": {
          "points": {
            "type": "integer",
            "minimum": 1
          },
          "expires": {
            "type": "integer"
          },
          "proof": {
            "type": "string"
          }
        }
      },
      "ReadingResult": {
        "type": "object",
        "required": [
          "ok",
          "status",
          "operation_id"
        ],
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "operation_id": {
            "type": "string",
            "pattern": "^pcr_[0-9a-f]{24}$"
          },
          "status": {
            "type": "string",
            "enum": [
              "reserved",
              "running",
              "completed",
              "released",
              "expired"
            ]
          },
          "charged_points": {
            "type": "integer",
            "minimum": 0
          },
          "report": {
            "type": "object"
          }
        }
      }
    }
  }
}
