{
  "openapi": "3.0.3",
  "info": {
    "title": "Court Booking API",
    "version": "1.0",
    "description": "Player-facing API of Novator Technologies Court & Facility Booking for Odoo. Times are local venue times in \"YYYY-MM-DD HH:MM\". Prices include tax."
  },
  "servers": [
    {
      "url": "https://{host}/api/booking/v1",
      "variables": {
        "host": {
          "default": "booking.example.com",
          "description": "The venue's Odoo website domain (staging or production)"
        }
      }
    }
  ],
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "Customer": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "phone": {
            "type": "string"
          },
          "login": {
            "type": "string"
          }
        }
      },
      "Token": {
        "type": "object",
        "properties": {
          "token": {
            "type": "string"
          },
          "token_type": {
            "type": "string"
          },
          "expires_at": {
            "type": "string"
          },
          "customer": {
            "$ref": "#/components/schemas/Customer"
          }
        }
      },
      "FacilityType": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "durations": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "step": {
            "type": "integer"
          },
          "currency": {
            "type": "string"
          },
          "payment": {
            "type": "string",
            "enum": [
              "venue",
              "deposit",
              "full"
            ]
          },
          "deposit_percent": {
            "type": "number"
          },
          "booking_window_days": {
            "type": "integer"
          },
          "cancel_hours": {
            "type": "integer"
          },
          "courts": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "integer"
                },
                "name": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "Availability": {
        "type": "object",
        "properties": {
          "type_id": {
            "type": "integer"
          },
          "date": {
            "type": "string"
          },
          "date_label": {
            "type": "string"
          },
          "duration": {
            "type": "integer"
          },
          "durations": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "today": {
            "type": "string"
          },
          "last_date": {
            "type": "string"
          },
          "periods": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "slots": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "start": {
                        "type": "string"
                      },
                      "label": {
                        "type": "string"
                      },
                      "end_label": {
                        "type": "string"
                      },
                      "from_amount": {
                        "type": "number"
                      },
                      "from_label": {
                        "type": "string"
                      },
                      "courts": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "integer"
                            },
                            "name": {
                              "type": "string"
                            },
                            "amount": {
                              "type": "number"
                            },
                            "amount_label": {
                              "type": "string"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "Booking": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "uuid": {
            "type": "string"
          },
          "reference": {
            "type": "string"
          },
          "facility_type": {
            "type": "object",
            "properties": {
              "id": {
                "type": "integer"
              },
              "name": {
                "type": "string"
              }
            }
          },
          "court": {
            "type": "object",
            "properties": {
              "id": {
                "type": "integer"
              },
              "name": {
                "type": "string"
              }
            }
          },
          "start": {
            "type": "string"
          },
          "stop": {
            "type": "string"
          },
          "date_label": {
            "type": "string"
          },
          "time_label": {
            "type": "string"
          },
          "duration": {
            "type": "integer"
          },
          "players": {
            "type": "integer"
          },
          "note": {
            "type": "string"
          },
          "state": {
            "type": "string"
          },
          "state_label": {
            "type": "string"
          },
          "currency": {
            "type": "string"
          },
          "amount": {
            "type": "number"
          },
          "amount_label": {
            "type": "string"
          },
          "paid_amount": {
            "type": "number"
          },
          "paid_amount_label": {
            "type": "string"
          },
          "amount_due": {
            "type": "number"
          },
          "amount_due_label": {
            "type": "string"
          },
          "payment_status": {
            "type": "string"
          },
          "online_payment": {
            "type": "string"
          },
          "amount_due_online": {
            "type": "number"
          },
          "hold_expires_at": {
            "type": "string",
            "nullable": true
          },
          "can_cancel": {
            "type": "boolean"
          },
          "cancel_blocked_reason": {
            "type": "string"
          },
          "channel": {
            "type": "string"
          },
          "past": {
            "type": "boolean"
          },
          "payment": {
            "type": "object",
            "properties": {
              "required_online": {
                "type": "boolean"
              },
              "amount": {
                "type": "number"
              },
              "pay_url": {
                "type": "string",
                "nullable": true,
                "description": "Open in an in-app browser to pay; poll the booking afterwards for its new state."
              }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/config": {
      "get": {
        "summary": "Venue, sign-in methods and facility types",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/facility-types": {
      "get": {
        "summary": "Facility types bookable online",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/FacilityType"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/availability": {
      "get": {
        "summary": "Free start times for one day",
        "parameters": [
          {
            "name": "facility_type_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "date",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "duration",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Availability"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or expired token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Rejected (slot taken, too late to cancel, wrong code...)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/auth/code": {
      "post": {
        "summary": "Send a one-time sign-in code by SMS or email",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "identifier": {
                    "type": "string",
                    "description": "Mobile number or email"
                  }
                },
                "required": [
                  "identifier"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "channel": {
                          "type": "string"
                        },
                        "sent_to": {
                          "type": "string"
                        },
                        "expires_in": {
                          "type": "integer"
                        },
                        "new_customer": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or expired token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Rejected (slot taken, too late to cancel, wrong code...)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/auth/verify": {
      "post": {
        "summary": "Check the code and get a token (creates the account for new customers)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "identifier": {
                    "type": "string"
                  },
                  "code": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string"
                  },
                  "email": {
                    "type": "string"
                  },
                  "device": {
                    "type": "string"
                  }
                },
                "required": [
                  "identifier",
                  "code"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Token"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or expired token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Rejected (slot taken, too late to cancel, wrong code...)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/auth/login": {
      "post": {
        "summary": "Sign in with email and password",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "login": {
                    "type": "string"
                  },
                  "password": {
                    "type": "string"
                  },
                  "device": {
                    "type": "string"
                  }
                },
                "required": [
                  "login",
                  "password"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Token"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or expired token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Rejected (slot taken, too late to cancel, wrong code...)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/auth/signup": {
      "post": {
        "summary": "Create an account with email and password",
        "description": "Ask for a code to the email with /auth/code first and send it as code: the email must be proven. phone is kept on the contact card only.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "email": {
                    "type": "string"
                  },
                  "phone": {
                    "type": "string"
                  },
                  "password": {
                    "type": "string"
                  },
                  "code": {
                    "type": "string"
                  },
                  "device": {
                    "type": "string"
                  }
                },
                "required": [
                  "name",
                  "email",
                  "password",
                  "code"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created"
          },
          "401": {
            "description": "Missing or expired token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Rejected (slot taken, too late to cancel, wrong code...)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/auth/logout": {
      "post": {
        "summary": "Sign this device out",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or expired token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Rejected (slot taken, too late to cancel, wrong code...)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/me": {
      "get": {
        "summary": "The signed-in customer",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Customer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or expired token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Rejected (slot taken, too late to cancel, wrong code...)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "summary": "Update name, email or phone",
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "email": {
                    "type": "string"
                  },
                  "phone": {
                    "type": "string"
                  }
                },
                "required": []
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Customer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or expired token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Rejected (slot taken, too late to cancel, wrong code...)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/bookings": {
      "get": {
        "summary": "My bookings",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "scope",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "upcoming",
                "past"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Booking"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or expired token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Rejected (slot taken, too late to cancel, wrong code...)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Book a court",
        "security": [
          {
            "bearer": []
          }
        ],
        "description": "Confirmed at once when paid at the venue, otherwise held until paid online (see payment.pay_url). Send a client_uuid so a retried request returns the same booking.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "facility_type_id": {
                    "type": "integer"
                  },
                  "start": {
                    "type": "string"
                  },
                  "duration": {
                    "type": "integer"
                  },
                  "court_id": {
                    "type": "integer"
                  },
                  "players": {
                    "type": "integer"
                  },
                  "note": {
                    "type": "string"
                  },
                  "client_uuid": {
                    "type": "string"
                  }
                },
                "required": [
                  "facility_type_id",
                  "start",
                  "duration"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Booking"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or expired token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Rejected (slot taken, too late to cancel, wrong code...)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/bookings/{id}": {
      "get": {
        "summary": "One booking",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Booking"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or expired token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Rejected (slot taken, too late to cancel, wrong code...)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/bookings/{id}/cancel": {
      "post": {
        "summary": "Cancel an unpaid booking before the cut-off",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "reason": {
                    "type": "string"
                  }
                },
                "required": []
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Booking"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or expired token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Rejected (slot taken, too late to cancel, wrong code...)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/bookings/{id}/payment-link": {
      "post": {
        "summary": "Payment page for what is due online",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or expired token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Rejected (slot taken, too late to cancel, wrong code...)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  }
}