{
 "openapi": "3.1.0",
 "info": {
  "title": "SuperPray",
  "version": "1.0.0",
  "description": "Start, read, update and end prayer vigils for a person who asked for one. See https://superpray.app/agents for the consent rules."
 },
 "servers": [
  {
   "url": "https://superpray.app"
  }
 ],
 "components": {
  "securitySchemes": {
   "editKey": {
    "type": "http",
    "scheme": "bearer",
    "description": "The editKey returned when the vigil was created."
   }
  },
  "schemas": {
   "Vigil": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "url": {
      "type": "string"
     },
     "name": {
      "type": "string"
     },
     "dream": {
      "type": "string"
     },
     "tradition": {
      "type": "string",
      "enum": [
       "universal",
       "christian",
       "catholic",
       "orthodox",
       "jewish",
       "muslim",
       "hindu",
       "buddhist",
       "sikh"
      ]
     },
     "share": {
      "type": "boolean"
     },
     "tier": {
      "type": "string",
      "enum": [
       "free",
       "paid"
      ]
     },
     "cadenceHours": {
      "type": "number"
     },
     "createdAt": {
      "type": "string",
      "format": "date-time"
     },
     "nextPrayerAt": {
      "type": "string",
      "format": "date-time"
     },
     "praying": {
      "type": "boolean"
     },
     "prayers": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "at": {
         "type": "string",
         "format": "date-time"
        },
        "text": {
         "type": "string"
        }
       }
      }
     }
    }
   }
  }
 },
 "paths": {
  "/api/vigils": {
   "post": {
    "operationId": "startVigil",
    "summary": "Start a vigil",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "dream": {
          "type": "string",
          "minLength": 8,
          "maxLength": 1200
         },
         "name": {
          "type": "string",
          "maxLength": 60
         },
         "tradition": {
          "type": "string",
          "enum": [
           "universal",
           "christian",
           "catholic",
           "orthodox",
           "jewish",
           "muslim",
           "hindu",
           "buddhist",
           "sikh"
          ]
         },
         "share": {
          "type": "boolean"
         },
         "consent": {
          "type": "boolean",
          "const": true,
          "description": "The person this vigil is for asked for it or clearly agreed."
         },
         "agent": {
          "type": "string",
          "maxLength": 80
         }
        },
        "required": [
         "dream",
         "consent"
        ]
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Created. Store editKey; it cannot be recovered.",
      "content": {
       "application/json": {
        "schema": {
         "allOf": [
          {
           "$ref": "#/components/schemas/Vigil"
          },
          {
           "type": "object",
           "properties": {
            "editKey": {
             "type": "string"
            }
           }
          }
         ]
        }
       }
      }
     },
     "400": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/api/vigils/{id}": {
   "parameters": [
    {
     "name": "id",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string",
      "pattern": "^[a-f0-9]{24}$"
     }
    }
   ],
   "get": {
    "operationId": "getVigil",
    "summary": "Read a vigil and its prayers",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Vigil"
        }
       }
      }
     },
     "404": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          }
         }
        }
       }
      }
     }
    }
   },
   "patch": {
    "operationId": "updateVigil",
    "summary": "Update the hope, name, tradition or wall sharing",
    "security": [
     {
      "editKey": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "dream": {
          "type": "string",
          "minLength": 8,
          "maxLength": 1200
         },
         "name": {
          "type": "string",
          "maxLength": 60
         },
         "tradition": {
          "type": "string",
          "enum": [
           "universal",
           "christian",
           "catholic",
           "orthodox",
           "jewish",
           "muslim",
           "hindu",
           "buddhist",
           "sikh"
          ]
         },
         "share": {
          "type": "boolean"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Vigil"
        }
       }
      }
     },
     "403": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          }
         }
        }
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "endVigil",
    "summary": "End a vigil and delete it permanently",
    "security": [
     {
      "editKey": []
     }
    ],
    "responses": {
     "200": {
      "description": "Deleted"
     },
     "403": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/api/traditions": {
   "get": {
    "operationId": "listTraditions",
    "summary": "List supported traditions",
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   }
  }
 }
}