{
  "openapi": "3.0.1",
  "info": {
    "title": "QuickRecall",
    "description": "Create flashcards and review them with spaced-repition.",
    "version": "v1"
  },
  "servers": [ { "url": "https://quickrecall.cards/api" } ],
  "components": {
    "schemas": {
      "Card": {
        "type": "object",
        "properties": {
          "front": { "type": "string" },
          "back": { "type": "string" }
        },
        "required": [ "front", "back" ]
      },
      "CardWithId": {
        "type": "object",
        "properties": {
          "front": { "type": "string" },
          "back": { "type": "string" },
          "id": { "type": "string" }
        },
        "required": [ "id", "front", "back" ]
      },
      "Practice": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "grade": {
            "type": "integer",
            "description": "0: forgot, 1: hard, 2: good, 3: easy",
            "enum": [ 0, 1, 2, 3 ]
          }
        },
        "required": [ "id", "grade" ]
      },
      "CardId": { "type": "object", "properties": { "id": { "type": "string" } }, "required": [ "id" ] },
      "Error": { "type": "object", "properties": { "errorMessage": { "type": "string" } }, "required": [ "errorMessage" ] }
    }
  },
  "paths": {
    "/createCard": {
      "post": {
        "operationId": "createCard",
        "summary": "Create a flashcard",
        "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Card" } } } },
        "responses": {
          "200": {
            "description": "The id of the created card",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CardId" } } }
          },
          "401": {
            "description": "Unauthorized",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
          },
          "500": {
            "description": "Internal Server Error",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
          }
        }
      }
    },
    "/getNextCardToReview": {
      "get": {
        "operationId": "getNextCardToReview",
        "summary": "Get the next card to review",
        "responses": {
          "200": {
            "description": "Card to review",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CardWithId" } } }
          },
          "401": {
            "description": "Unauthorized",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
          },
          "500": {
            "description": "Internal Server Error",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
          }
        }
      }
    },
    "/recordCardPractice": {
      "post": {
        "operationId": "recordCardPractice",
        "summary": "Record the practice of a flashcard",
        "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Practice" } } } },
        "responses": {
          "200": {
            "description": "Id of successfully practiced card.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CardId" } } }
          },
          "400": {
            "description": "Invalid request",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
          },
          "401": {
            "description": "Unauthorized",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
          },
          "500": {
            "description": "Internal Server Error",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
          }
        }
      }
    },
    "/updateCard": {
      "post": {
        "operationId": "updateCard",
        "summary": "Update a flashcard",
        "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Card" } } } },
        "responses": {
          "200": {
            "description": "Id of successfully updated card.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CardId" } } }
          },
          "401": {
            "description": "Unauthorized",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
          },
          "500": {
            "description": "Internal Server Error",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
          }
        }
      }
    },
    "/deleteCard": {
      "post": {
        "operationId": "deleteCard",
        "summary": "Delete a flashcard",
        "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CardId" } } } },
        "responses": {
          "200": {
            "description": "Id of successfully deleted card.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CardId" } } }
          },
          "401": {
            "description": "Unauthorized",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
          },
          "500": {
            "description": "Internal Server Error",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
          }
        }
      }
    }
  }
}