{
  "openapi": "3.0.1",
  "info": {
    "title": "PetalPal | v1",
    "version": "1.0.0"
  },
  "paths": {
    "/api/gardens/plants": {
      "get": {
        "tags": [
          "GardenApi"
        ],
        "summary": "List plants",
        "description": "List every plant in the signed-in user's PetalPal garden. Returns id, name, kind, health (lush/healthy/thirsty/wilted), stage (sprout/seedling/growing/mature), waterCount, lastWateredAt, and createdAt.",
        "operationId": "list_plants",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GardenSnapshotDto"
                }
              }
            }
          }
        },
        "security": [
          {
            "Bearer": [ ]
          }
        ]
      },
      "post": {
        "tags": [
          "GardenApi"
        ],
        "summary": "Create plant",
        "description": "Add a plant to the signed-in user's garden. kind must be one of: basil, fern, mint, succulent, daisy. The new plant starts as a thirsty sprout.",
        "operationId": "create_plant",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreatePlantRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreatePlantToolDto"
                }
              }
            }
          }
        },
        "security": [
          {
            "Bearer": [ ]
          }
        ]
      }
    },
    "/api/gardens/plants/{plantId}/water": {
      "post": {
        "tags": [
          "GardenApi"
        ],
        "summary": "Water plant",
        "description": "Water one plant by id. Use list_plants first if you do not know the id.",
        "operationId": "water_plant",
        "parameters": [
          {
            "name": "plantId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WaterPlantToolDto"
                }
              }
            }
          }
        },
        "security": [
          {
            "Bearer": [ ]
          }
        ]
      }
    },
    "/api/gardens/plants/water-thirsty": {
      "post": {
        "tags": [
          "GardenApi"
        ],
        "summary": "Water thirsty plants",
        "description": "Find every thirsty or wilted plant and water each one. Use when the user asks to water thirsty plants without naming them.",
        "operationId": "water_thirsty_plants",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WaterThirstyToolDto"
                }
              }
            }
          }
        },
        "security": [
          {
            "Bearer": [ ]
          }
        ]
      }
    },
    "/api/gardens/me": {
      "get": {
        "tags": [
          "GardenApi"
        ],
        "summary": "Get one page of the garden",
        "description": "Paged view of the signed-in user's garden for the web UI. Pass cursor and pageSize; follow nextCursor while hasNextPage is true.",
        "operationId": "get_garden_page",
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "description": "Opaque nextCursor from the previous page. Omit for the first page.",
            "schema": {
              "type": "string",
              "default": null
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "description": "Plant page size (1-100). Defaults to 10.",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GardenPageDto"
                }
              }
            }
          }
        },
        "security": [
          {
            "Bearer": [ ]
          }
        ]
      }
    },
    "/sqlos/auth/password/login": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Get tokens with email and password",
        "description": "First-party only. This is not the OAuth way to log in. Create an account on the hosted auth page, then call this with clientId `petalpal`. Leave organizationId null — SqlOS signs you into your only organization and returns tokens. If you belong to more than one, you get requiresOrganizationSelection and a pendingAuthToken instead. Paste tokens.accessToken into Authorize to try the garden tools.",
        "operationId": "password_login",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "required": [
                  "email",
                  "password",
                  "clientId"
                ],
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "example": "you@example.com"
                  },
                  "password": {
                    "type": "string",
                    "format": "password"
                  },
                  "clientId": {
                    "type": "string",
                    "default": "petalpal"
                  },
                  "organizationId": {
                    "type": "string",
                    "description": "Leave null. That is the usual path: one org → tokens for that org; no org → tokens with no organization; several orgs → requiresOrganizationSelection instead of tokens. Pass an id only when you already know which organization to use.",
                    "nullable": true
                  }
                }
              },
              "example": {
                "email": "you@example.com",
                "password": "your-password",
                "clientId": "petalpal",
                "organizationId": null
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "With organizationId null: tokens for your only organization, or requiresOrganizationSelection=true if you belong to more than one. May also ask for MFA.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "requiresOrganizationSelection": {
                      "type": "boolean"
                    },
                    "pendingAuthToken": {
                      "type": "string",
                      "nullable": true
                    },
                    "requiresMfa": {
                      "type": "boolean"
                    },
                    "mfaToken": {
                      "type": "string",
                      "nullable": true
                    },
                    "tokens": {
                      "type": "object",
                      "properties": {
                        "accessToken": {
                          "type": "string"
                        },
                        "refreshToken": {
                          "type": "string"
                        },
                        "sessionId": {
                          "type": "string"
                        },
                        "clientId": {
                          "type": "string"
                        },
                        "organizationId": {
                          "type": "string",
                          "nullable": true
                        }
                      },
                      "nullable": true
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "CreatePlantRequest": {
        "required": [
          "kind"
        ],
        "type": "object",
        "properties": {
          "kind": {
            "type": "string",
            "description": "Plant kind to add: basil, fern, mint, succulent, or daisy."
          }
        }
      },
      "CreatePlantToolDto": {
        "required": [
          "ok",
          "kind",
          "garden"
        ],
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "kind": {
            "type": "string"
          },
          "garden": {
            "$ref": "#/components/schemas/GardenSnapshotDto"
          }
        }
      },
      "GardenPageDto": {
        "required": [
          "id",
          "name",
          "createdAt",
          "plants",
          "pageSize",
          "nextCursor",
          "hasNextPage"
        ],
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "plants": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PlantDto"
            }
          },
          "pageSize": {
            "type": "integer",
            "format": "int32"
          },
          "nextCursor": {
            "type": "string",
            "nullable": true
          },
          "hasNextPage": {
            "type": "boolean"
          }
        }
      },
      "GardenSnapshotDto": {
        "required": [
          "id",
          "name",
          "createdAt",
          "plantCount",
          "plants"
        ],
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "plantCount": {
            "type": "integer",
            "format": "int32"
          },
          "plants": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PlantCardDto"
            }
          }
        }
      },
      "PlantCardDto": {
        "required": [
          "id",
          "name",
          "kind",
          "health",
          "waterCount",
          "lastWateredAt",
          "createdAt",
          "stage"
        ],
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "kind": {
            "type": "string"
          },
          "health": {
            "type": "string"
          },
          "waterCount": {
            "type": "integer",
            "format": "int32"
          },
          "lastWateredAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "stage": {
            "type": "string"
          }
        }
      },
      "PlantDto": {
        "required": [
          "id",
          "name",
          "mood",
          "note",
          "waterCount",
          "lastWateredAt",
          "health",
          "createdAt",
          "stage"
        ],
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "mood": {
            "type": "string"
          },
          "note": {
            "type": "string"
          },
          "waterCount": {
            "type": "integer",
            "format": "int32"
          },
          "lastWateredAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "health": {
            "type": "string",
            "description": "Computed plant health: lush, healthy, thirsty, or wilted, derived from lastWateredAt."
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "stage": {
            "type": "string",
            "description": "Computed growth stage: sprout, seedling, growing, or mature, derived from createdAt."
          }
        }
      },
      "WateredPlantDto": {
        "required": [
          "id",
          "name",
          "kind"
        ],
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "kind": {
            "type": "string"
          }
        }
      },
      "WaterPlantToolDto": {
        "required": [
          "ok",
          "plant",
          "garden"
        ],
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "plant": {
            "$ref": "#/components/schemas/PlantCardDto"
          },
          "garden": {
            "$ref": "#/components/schemas/GardenSnapshotDto"
          }
        }
      },
      "WaterThirstyToolDto": {
        "required": [
          "wateredCount",
          "watered",
          "garden"
        ],
        "type": "object",
        "properties": {
          "wateredCount": {
            "type": "integer",
            "format": "int32"
          },
          "watered": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WateredPlantDto"
            }
          },
          "garden": {
            "$ref": "#/components/schemas/GardenSnapshotDto"
          }
        }
      }
    },
    "securitySchemes": {
      "Bearer": {
        "type": "http",
        "description": "Paste the access_token from POST /sqlos/auth/password/login. Garden routes need audience {origin}/api. Browser users should sign in through /sqlos/auth instead.",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    }
  },
  "tags": [
    {
      "name": "GardenApi"
    },
    {
      "name": "Auth",
      "description": "First-party SqlOS credential API. Not the OAuth login path — browsers and third-party clients should use the hosted auth page."
    }
  ]
}