{
  "openapi": "3.0.3",
  "info": {
    "title": "Campsite Authentication APIs",
    "version": "1.0.0",
    "description": "Per-campsite login, forgot password, reset password, and forgot username endpoints."
  },
  "servers": [
    {
      "url": "{{baseUrl}}",
      "description": "Base URL (set baseUrl variable in Apidog environment)"
    }
  ],
  "tags": [
    {
      "name": "Campsite Auth",
      "description": "Authentication endpoints for campsite login"
    }
  ],
  "paths": {
    "/api/auth/campsite/login": {
      "post": {
        "tags": ["Campsite Auth"],
        "summary": "Campsite Login",
        "description": "Login using campsite username and password. Returns a JWT access token and refresh token scoped to the campsite.",
        "operationId": "campsiteLogin",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["username", "password"],
                "properties": {
                  "username": {
                    "type": "string",
                    "example": "alpine_hut_x7k2"
                  },
                  "password": {
                    "type": "string",
                    "example": "TempPass@1234"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Login successful",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean", "example": true },
                    "message": { "type": "string", "example": "Login successful" },
                    "data": {
                      "type": "object",
                      "properties": {
                        "campsite": {
                          "type": "object",
                          "properties": {
                            "id":       { "type": "string", "example": "664f1a2b3c4d5e6f7a8b9c0d" },
                            "name":     { "type": "string", "example": "Alpine Hut" },
                            "username": { "type": "string", "example": "alpine_hut_x7k2" }
                          }
                        },
                        "tokens": {
                          "type": "object",
                          "properties": {
                            "accessToken":  { "type": "string" },
                            "refreshToken": { "type": "string" }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid credentials",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" },
                "example": { "success": false, "message": "Invalid credentials" }
              }
            }
          },
          "403": {
            "description": "Campsite is inactive",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" },
                "example": { "success": false, "message": "This campsite is not active. Please contact the administrator." }
              }
            }
          }
        }
      }
    },
    "/api/auth/campsite/forgot-password": {
      "post": {
        "tags": ["Campsite Auth"],
        "summary": "Campsite Forgot Password",
        "description": "Send a password reset link to the campsite owner's email. Accepts the campsite username. Always returns success regardless of whether the username exists (security best practice).",
        "operationId": "campsiteForgotPassword",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["username"],
                "properties": {
                  "username": {
                    "type": "string",
                    "example": "alpine_hut_x7k2"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Reset link sent (or silently ignored if username not found)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean", "example": true },
                    "message": { "type": "string", "example": "Password reset instructions sent" },
                    "data": {
                      "type": "object",
                      "properties": {
                        "success": { "type": "boolean", "example": true }
                      }
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Validation error — username is required",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/api/auth/campsite/reset-password": {
      "post": {
        "tags": ["Campsite Auth"],
        "summary": "Campsite Reset Password",
        "description": "Reset the campsite password using the token received in the forgot-password email. Token expires in 1 hour.",
        "operationId": "campsiteResetPassword",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["token", "newPassword"],
                "properties": {
                  "token": {
                    "type": "string",
                    "example": "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4"
                  },
                  "newPassword": {
                    "type": "string",
                    "minLength": 6,
                    "example": "NewSecurePass@99"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Password reset successful",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean", "example": true },
                    "message": { "type": "string", "example": "Password reset successful" },
                    "data": {
                      "type": "object",
                      "properties": {
                        "success": { "type": "boolean", "example": true }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid or expired token",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" },
                "example": { "success": false, "message": "Invalid token" }
              }
            }
          }
        }
      }
    },
    "/api/auth/campsite/forgot-username": {
      "post": {
        "tags": ["Campsite Auth"],
        "summary": "Campsite Forgot Username",
        "description": "Send the campsite username to the owner's email. Requires the owner's registered email and the campsite name (case-insensitive match). Always returns success regardless of match (security best practice).",
        "operationId": "campsiteForgotUsername",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["email", "campsite_name"],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "example": "owner@example.com"
                  },
                  "campsite_name": {
                    "type": "string",
                    "example": "Alpine Hut"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Username sent (or silently ignored if no match found)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean", "example": true },
                    "message": { "type": "string", "example": "If an account matches the details provided, the username has been sent to the registered email" },
                    "data": {
                      "type": "object",
                      "properties": {
                        "success": { "type": "boolean", "example": true }
                      }
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Validation error — email and campsite_name are required",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "example": false },
          "message": { "type": "string", "example": "Error message" }
        }
      }
    }
  }
}
