{
  "openapi": "3.1.0",
  "info": {
    "title": "api",
    "description": "API for sapa-tv.ru",
    "license": {
      "name": ""
    },
    "version": "v0"
  },
  "paths": {
    "/api/health": {
      "get": {
        "tags": [
          "Health"
        ],
        "operationId": "health",
        "responses": {
          "200": {
            "description": "Health check",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/king": {
      "get": {
        "tags": [
          "King"
        ],
        "operationId": "get_king",
        "responses": {
          "200": {
            "description": "Current king",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/KingResponse"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "King"
        ],
        "operationId": "post_king",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/KingRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Update king",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/KingResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/last-day": {
      "get": {
        "tags": [
          "Donaters"
        ],
        "operationId": "get_last_day",
        "responses": {
          "200": {
            "description": "Donaters for last day",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DonatersResponse"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Donaters"
        ],
        "operationId": "post_last_day",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DonaterRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Add last day donater",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DonatersResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/month": {
      "get": {
        "tags": [
          "Donaters"
        ],
        "operationId": "get_month",
        "responses": {
          "200": {
            "description": "Donaters for current month",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DonatersResponse"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Donaters"
        ],
        "operationId": "post_month",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DonaterRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Add month donater",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DonatersResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/oauth/callback": {
      "get": {
        "tags": [
          "OAuth"
        ],
        "operationId": "oauth_callback",
        "responses": {
          "200": {
            "description": "OAuth callback result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OAuthCallbackResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/oauth/url": {
      "get": {
        "tags": [
          "OAuth"
        ],
        "operationId": "get_oauth_url",
        "responses": {
          "200": {
            "description": "Twitch OAuth authorization URL",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OAuthUrlResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/push/subscription": {
      "post": {
        "tags": [
          "Push"
        ],
        "operationId": "post_subscription",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PushSubscriptionRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Save push subscription",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PushSubscriptionResponse"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Push"
        ],
        "operationId": "delete_subscription",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PushSubscriptionRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Delete push subscription",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PushSubscriptionResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/push/test-all": {
      "post": {
        "tags": [
          "Push"
        ],
        "operationId": "test_push_all",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PushTestRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Send test push to all subscriptions",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PushTestResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/push/vapid-public-key": {
      "get": {
        "tags": [
          "Push"
        ],
        "operationId": "get_vapid_public_key",
        "responses": {
          "200": {
            "description": "VAPID public key for push notifications",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VapidPublicKeyResponse"
                }
              }
            }
          },
          "500": {
            "description": "VAPID_PUBLIC_KEY not configured"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "DonaterRequest": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string"
          }
        }
      },
      "DonatersResponse": {
        "type": "object",
        "required": [
          "donaters"
        ],
        "properties": {
          "donaters": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "example": [
          "Star",
          "Echo"
        ]
      },
      "HealthResponse": {
        "type": "object",
        "required": [
          "status",
          "version",
          "commit"
        ],
        "properties": {
          "commit": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "version": {
            "type": "string"
          }
        }
      },
      "KingRequest": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string"
          }
        }
      },
      "KingResponse": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string"
          }
        },
        "example": {
          "name": "Star"
        }
      },
      "OAuthCallbackParams": {
        "type": "object",
        "required": [
          "code"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "state": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "OAuthCallbackResponse": {
        "type": "object",
        "required": [
          "success",
          "message"
        ],
        "properties": {
          "message": {
            "type": "string"
          },
          "success": {
            "type": "boolean"
          }
        }
      },
      "OAuthUrlResponse": {
        "type": "object",
        "required": [
          "url"
        ],
        "properties": {
          "url": {
            "type": "string"
          }
        }
      },
      "PushKeys": {
        "type": "object",
        "required": [
          "p256dh",
          "auth"
        ],
        "properties": {
          "auth": {
            "type": "string"
          },
          "p256dh": {
            "type": "string"
          }
        }
      },
      "PushSubscriptionRequest": {
        "type": "object",
        "required": [
          "endpoint",
          "keys"
        ],
        "properties": {
          "endpoint": {
            "type": "string"
          },
          "keys": {
            "$ref": "#/components/schemas/PushKeys"
          },
          "user_id": {
            "type": [
              "string",
              "null"
            ],
            "example": null
          }
        }
      },
      "PushSubscriptionResponse": {
        "type": "object",
        "required": [
          "success"
        ],
        "properties": {
          "success": {
            "type": "boolean"
          }
        }
      },
      "PushTestRequest": {
        "type": "object",
        "required": [
          "title",
          "body"
        ],
        "properties": {
          "body": {
            "type": "string"
          },
          "title": {
            "type": "string"
          }
        }
      },
      "PushTestResponse": {
        "type": "object",
        "required": [
          "sent"
        ],
        "properties": {
          "sent": {
            "type": "integer",
            "format": "int32",
            "minimum": 0
          }
        }
      },
      "VapidPublicKeyResponse": {
        "type": "object",
        "required": [
          "key"
        ],
        "properties": {
          "key": {
            "type": "string"
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "Health",
      "description": "Health check"
    },
    {
      "name": "King",
      "description": "King operations"
    },
    {
      "name": "Donaters",
      "description": "Donaters operations"
    },
    {
      "name": "Push",
      "description": "Web Push notifications"
    },
    {
      "name": "OAuth",
      "description": "Twitch OAuth authorization"
    }
  ]
}