{
  "openapi": "3.1.0",
  "info": {
    "title": "Aligner Calculator API",
    "description": "HTTP API for calculating aligner tray change dates.",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://calculator.glamour.dental"
    }
  ],
  "paths": {
    "/api/aligner": {
      "get": {
        "operationId": "calculateAlignerSchedule",
        "summary": "Calculate aligner tray change dates",
        "description": "Returns scheduled change dates for a future range of aligner trays.",
        "parameters": [
          {
            "name": "currentTray",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "description": "Current aligner tray number."
          },
          {
            "name": "nextTrayFrom",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "description": "First future tray number to include. Must be greater than currentTray."
          },
          {
            "name": "nextTrayTo",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "description": "Last future tray number to include. Must be greater than or equal to nextTrayFrom."
          },
          {
            "name": "daysPerTray",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "description": "Number of days each aligner tray is worn."
          },
          {
            "name": "startDate",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            },
            "description": "Date for the current tray in YYYY-MM-DD format."
          }
        ],
        "responses": {
          "200": {
            "description": "Calculated aligner schedule.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AlignerScheduleResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid query parameters.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "405": {
            "description": "Method not allowed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "AlignerScheduleResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "currentTray",
          "nextTrayFrom",
          "nextTrayTo",
          "daysPerTray",
          "startDate",
          "schedule"
        ],
        "properties": {
          "currentTray": {
            "type": "integer",
            "minimum": 1
          },
          "nextTrayFrom": {
            "type": "integer",
            "minimum": 1
          },
          "nextTrayTo": {
            "type": "integer",
            "minimum": 1
          },
          "daysPerTray": {
            "type": "integer",
            "minimum": 1
          },
          "startDate": {
            "type": "string",
            "format": "date"
          },
          "schedule": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AlignerScheduleItem"
            }
          }
        }
      },
      "AlignerScheduleItem": {
        "type": "object",
        "additionalProperties": false,
        "required": ["tray", "date"],
        "properties": {
          "tray": {
            "type": "integer",
            "minimum": 1
          },
          "date": {
            "type": "string",
            "format": "date"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": ["error"],
        "properties": {
          "error": {
            "type": "string"
          },
          "details": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      }
    }
  }
}
