{
  "openapi": "3.1.0",
  "info": {
    "title": "Chauncey Ranch Dental booking API",
    "version": "0.1.0",
    "description": "Office-hours time windows and appointment requests. Booking takes the minimum: reason, time, name and phone. No scheduling vendor is connected yet: /api/availability returns the office-hours windows with live=false, and a request is only a request; the office texts to confirm. In production without a vendor, /api/book returns 503 not_configured."
  },
  "servers": [
    {
      "url": "https://chaunceyranchdental.com"
    }
  ],
  "paths": {
    "/api/availability": {
      "get": {
        "operationId": "getAvailability",
        "summary": "List open appointment slots",
        "responses": {
          "200": {
            "description": "Open slots. Empty with configured=false when no scheduler is connected.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Availability"
                }
              }
            }
          }
        }
      }
    },
    "/api/book": {
      "post": {
        "operationId": "requestAppointment",
        "summary": "Request an appointment",
        "description": "Send as form data. Fields come from /facts.json (booking.reasons, booking.preferences) and /api/availability (slot starts). Send Accept: application/json for a JSON reply; browsers sending Accept: text/html get a 303 redirect to /book/sent or /book/unavailable.",
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/BookingRequest"
              }
            },
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/BookingRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Request received. Not a confirmed appointment: the office texts to confirm.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BookingAccepted"
                }
              }
            }
          },
          "303": {
            "description": "Redirect for browsers without JavaScript"
          },
          "422": {
            "description": "A field is missing or invalid",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "No scheduler connected (error: not_configured)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Availability": {
        "type": "object",
        "required": [
          "configured",
          "windows",
          "slots"
        ],
        "properties": {
          "configured": {
            "type": "boolean"
          },
          "live": {
            "type": "boolean",
            "description": "true only when a vendor supplies real open slots"
          },
          "timeZone": {
            "type": "string"
          },
          "windows": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "example": "window:tu-0700"
                },
                "day": {
                  "type": "string",
                  "example": "Tu"
                },
                "start": {
                  "type": "string",
                  "example": "07:00"
                },
                "end": {
                  "type": "string",
                  "example": "09:00"
                }
              }
            }
          },
          "slots": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "start": {
                  "type": "string",
                  "format": "date-time"
                },
                "minutes": {
                  "type": "integer"
                }
              }
            }
          }
        }
      },
      "BookingRequest": {
        "type": "object",
        "required": [
          "reason",
          "time",
          "name",
          "phone"
        ],
        "properties": {
          "reason": {
            "type": "string",
            "enum": [
              "new-patient",
              "cleaning",
              "pain",
              "veneer-consult",
              "cosmetic",
              "other"
            ]
          },
          "time": {
            "type": "string",
            "description": "first-available, or a window id from /api/availability (one of: window:tu-0900, window:tu-1100, window:tu-1300, window:tu-1500, window:we-0900, window:we-1100, window:we-1300, window:we-1500, window:th-0900, window:th-1100, window:th-1300, window:th-1500, window:fr-0900, window:fr-1100, window:fr-1300, window:fr-1500), or an ISO 8601 slot start once a vendor supplies live slots"
          },
          "name": {
            "type": "string",
            "maxLength": 80
          },
          "phone": {
            "type": "string",
            "description": "10 to 15 digits; formatting characters are ignored"
          }
        }
      },
      "BookingAccepted": {
        "type": "object",
        "properties": {
          "ok": {
            "const": true
          },
          "reference": {
            "type": "string"
          },
          "status": {
            "const": "requested",
            "description": "The office texts the patient to confirm; this is not a confirmed appointment."
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "ok": {
            "const": false
          },
          "error": {
            "type": "string"
          },
          "fields": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "message": {
            "type": "string"
          }
        }
      }
    }
  }
}