{
  "openapi": "3.0.0",
  "info": {
    "title": "Agent Wiki API",
    "version": "1.0.0",
    "description": "API documentation for Agent Wiki"
  },
  "servers": [
    {
      "url": "/v1",
      "description": "API v1"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    },
    "schemas": {
      "User": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "username": { "type": "string" },
          "email": { "type": "string", "format": "email" },
          "role": { "type": "string", "enum": ["superadmin", "admin", "editor"] },
          "organization": { "type": "string" }
        }
      },
      "Organization": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "vat": { "type": "string" },
          "address": { "type": "string" },
          "phone": { "type": "string" },
          "city": { "type": "string" },
          "zip": { "type": "string" },
          "country": { "type": "string" },
          "logo": { "type": "string", "format": "uri" },
          "tierId": { "type": "string" }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "message": { "type": "string" }
        }
      }
    }
  },
  "paths": {
    "/auth/login": {
      "post": {
        "tags": ["Authentication"],
        "summary": "Login user",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["email", "password"],
                "properties": {
                  "email": { "type": "string", "format": "email" },
                  "password": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Login successful",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "token": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/auth/signup": {
      "post": {
        "tags": ["Authentication"],
        "summary": "Sign up new user",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["username", "email", "password", "tierId", "paymentMethod", "organization"],
                "properties": {
                  "username": { "type": "string" },
                  "email": { "type": "string", "format": "email" },
                  "password": { "type": "string" },
                  "tierId": { "type": "string" },
                  "paymentMethod": { "type": "string" },
                  "organization": {
                    "type": "object",
                    "required": ["name", "vat"],
                    "properties": {
                      "name": { "type": "string" },
                      "vat": { "type": "string" },
                      "address": { "type": "string" },
                      "phone": { "type": "string" },
                      "city": { "type": "string" },
                      "zip": { "type": "string" },
                      "country": { "type": "string" }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "User created successfully"
          }
        }
      }
    },
    "/auth/send-reset": {
      "post": {
        "tags": ["Authentication"],
        "summary": "Send password reset email",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["email"],
                "properties": {
                  "email": { "type": "string", "format": "email" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Reset email sent successfully"
          }
        }
      }
    },
    "/auth/reset": {
      "post": {
        "tags": ["Authentication"],
        "summary": "Reset password",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["password", "token"],
                "properties": {
                  "password": { "type": "string" },
                  "token": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Password reset successful"
          }
        }
      }
    },
    "/auth/verify": {
      "post": {
        "tags": ["Authentication"],
        "summary": "Verify reset password token",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["token"],
                "properties": {
                  "token": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Token is valid"
          }
        }
      }
    },
    "/auth/logout": {
      "get": {
        "tags": ["Authentication"],
        "summary": "Logout user",
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": {
            "description": "Logout successful"
          }
        }
      }
    },
    "/user": {
      "get": {
        "tags": ["User"],
        "summary": "Get current user",
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": {
            "description": "Current user details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/User"
                }
              }
            }
          }
        }
      },
      "put": {
        "tags": ["User"],
        "summary": "Edit current user",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["username"],
                "properties": {
                  "username": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "User updated successfully"
          }
        }
      },
      "post": {
        "tags": ["User"],
        "summary": "Add new user (Admin only)",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["username", "email", "role", "organization"],
                "properties": {
                  "username": { "type": "string" },
                  "email": { "type": "string", "format": "email" },
                  "role": { "type": "string", "enum": ["superadmin", "admin", "editor"] },
                  "organization": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "User created successfully"
          }
        }
      }
    },
    "/users": {
      "post": {
        "tags": ["User"],
        "summary": "Get users list (Admin only)",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["perPage", "pageNumber"],
                "properties": {
                  "perPage": { "type": "integer" },
                  "pageNumber": { "type": "integer" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "List of users",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "users": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/User"
                      }
                    },
                    "total": { "type": "integer" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/user/{id}": {
      "get": {
        "tags": ["User"],
        "summary": "Get user by ID (Admin only)",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "User details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/User"
                }
              }
            }
          }
        }
      },
      "put": {
        "tags": ["User"],
        "summary": "Edit user (Admin only)",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["username", "role", "organization"],
                "properties": {
                  "username": { "type": "string" },
                  "role": { "type": "string", "enum": ["superadmin", "admin", "editor"] },
                  "organization": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "User updated successfully"
          }
        }
      },
      "delete": {
        "tags": ["User"],
        "summary": "Delete user (Admin only)",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "User deleted successfully"
          }
        }
      }
    },
    "/organization": {
      "get": {
        "tags": ["Organization"],
        "summary": "Get current organization",
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": {
            "description": "Organization details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Organization"
                }
              }
            }
          }
        }
      },
      "put": {
        "tags": ["Organization"],
        "summary": "Edit current organization (Admin only)",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["name", "vat"],
                "properties": {
                  "name": { "type": "string" },
                  "vat": { "type": "string" },
                  "address": { "type": "string" },
                  "phone": { "type": "string" },
                  "city": { "type": "string" },
                  "zip": { "type": "string" },
                  "country": { "type": "string" },
                  "logo": { "type": "string", "format": "uri" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Organization updated successfully"
          }
        }
      },
      "post": {
        "tags": ["Organization"],
        "summary": "Create new organization (Super Admin only)",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["name", "vat"],
                "properties": {
                  "name": { "type": "string" },
                  "vat": { "type": "string" },
                  "phone": { "type": "string" },
                  "address": { "type": "string" },
                  "city": { "type": "string" },
                  "zip": { "type": "string" },
                  "country": { "type": "string" },
                  "logo": { "type": "string", "format": "uri" },
                  "tierId": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Organization created successfully"
          }
        }
      }
    },
    "/organization/{id}": {
      "get": {
        "tags": ["Organization"],
        "summary": "Get organization by ID (Super Admin only)",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Organization details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Organization"
                }
              }
            }
          }
        }
      },
      "put": {
        "tags": ["Organization"],
        "summary": "Edit organization (Super Admin only)",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["name", "vat"],
                "properties": {
                  "name": { "type": "string" },
                  "vat": { "type": "string" },
                  "address": { "type": "string" },
                  "phone": { "type": "string" },
                  "city": { "type": "string" },
                  "zip": { "type": "string" },
                  "country": { "type": "string" },
                  "logo": { "type": "string", "format": "uri" },
                  "tierId": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Organization updated successfully"
          }
        }
      },
      "delete": {
        "tags": ["Organization"],
        "summary": "Delete organization (Super Admin only)",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Organization deleted successfully"
          }
        }
      }
    },
    "/organizations": {
      "post": {
        "tags": ["Organization"],
        "summary": "Get organizations list (Super Admin only)",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["perPage", "pageNumber"],
                "properties": {
                  "perPage": { "type": "integer" },
                  "pageNumber": { "type": "integer" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "List of organizations",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "organizations": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Organization"
                      }
                    },
                    "total": { "type": "integer" }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
