{
  "openapi": "3.0.3",
  "info": {
    "title": "Elsewhere scoped Agent API",
    "version": "1.0.3",
    "description": "Owner-approved manual bearer credentials remain active until disconnected; write operations only affect private stays."
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "components": {
    "securitySchemes": {
      "agentBearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "Credential from Agent access; active until the owner disconnects it"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "Human-readable reason and recovery guidance."
          }
        }
      }
    }
  },
  "paths": {
    "/api/cities": {
      "get": {
        "summary": "Public destination lookup",
        "parameters": [
          {
            "in": "query",
            "name": "q",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Destination list with IDs",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "required": [
                      "id",
                      "name",
                      "country",
                      "state",
                      "kind",
                      "lat",
                      "lon",
                      "region"
                    ],
                    "properties": {
                      "id": {
                        "type": "string"
                      },
                      "name": {
                        "type": "string"
                      },
                      "country": {
                        "type": "string"
                      },
                      "state": {
                        "type": "string"
                      },
                      "kind": {
                        "type": "string"
                      },
                      "region": {
                        "type": "string"
                      },
                      "lat": {
                        "type": "number"
                      },
                      "lon": {
                        "type": "number"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "operationId": "searchDestinations",
        "description": "Public catalog. q matches city/park, state, region or country; query results are capped at 30. Use returned IDs and disambiguate names. Omitting q returns the full catalog."
      }
    },
    "/api/plans": {
      "get": {
        "summary": "List own plans (plans:read required)",
        "security": [
          {
            "agentBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Array of the owner's plans, including private notes; plans:read required.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "required": [
                      "id",
                      "city",
                      "start",
                      "end",
                      "status",
                      "visibility",
                      "note"
                    ],
                    "properties": {
                      "id": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "city": {
                        "type": "string"
                      },
                      "start": {
                        "type": "string",
                        "format": "date"
                      },
                      "end": {
                        "type": "string",
                        "format": "date"
                      },
                      "status": {
                        "type": "string",
                        "enum": [
                          "tentative",
                          "confirmed"
                        ]
                      },
                      "visibility": {
                        "type": "string",
                        "enum": [
                          "private",
                          "community"
                        ],
                        "description": "community is legacy storage for Friends visibility; it does not mean public."
                      },
                      "note": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired or revoked credential",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Permission denied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "operationId": "listPlans"
      },
      "post": {
        "summary": "Create private stay; exact duplicates reuse existing ID",
        "security": [
          {
            "agentBearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "city",
                  "start",
                  "end",
                  "status"
                ],
                "properties": {
                  "city": {
                    "type": "string",
                    "description": "ID from /api/cities"
                  },
                  "start": {
                    "type": "string",
                    "format": "date",
                    "description": "Destination-local calendar date, inclusive. Allowed range 2000-01-01 through 2100-12-31. End must be on/after start; different cities cannot overlap on any inclusive day."
                  },
                  "end": {
                    "type": "string",
                    "format": "date",
                    "description": "Destination-local calendar date, inclusive. Allowed range 2000-01-01 through 2100-12-31. End must be on/after start; different cities cannot overlap on any inclusive day."
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "tentative",
                      "confirmed"
                    ]
                  },
                  "visibility": {
                    "type": "string",
                    "enum": [
                      "private"
                    ],
                    "default": "private"
                  },
                  "note": {
                    "type": "string",
                    "maxLength": 280
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success or exact existing plan (reused:true)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "city",
                    "start",
                    "end",
                    "status",
                    "visibility",
                    "note",
                    "id",
                    "reused"
                  ],
                  "properties": {
                    "city": {
                      "type": "string",
                      "description": "ID from /api/cities"
                    },
                    "start": {
                      "type": "string",
                      "format": "date"
                    },
                    "end": {
                      "type": "string",
                      "format": "date"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "tentative",
                        "confirmed"
                      ]
                    },
                    "visibility": {
                      "type": "string",
                      "enum": [
                        "private"
                      ],
                      "default": "private"
                    },
                    "note": {
                      "type": "string",
                      "maxLength": 280
                    },
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "reused": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Plan created with id",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "city",
                    "start",
                    "end",
                    "status",
                    "visibility",
                    "note",
                    "id"
                  ],
                  "properties": {
                    "city": {
                      "type": "string",
                      "description": "ID from /api/cities"
                    },
                    "start": {
                      "type": "string",
                      "format": "date"
                    },
                    "end": {
                      "type": "string",
                      "format": "date"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "tentative",
                        "confirmed"
                      ]
                    },
                    "visibility": {
                      "type": "string",
                      "enum": [
                        "private"
                      ],
                      "default": "private"
                    },
                    "note": {
                      "type": "string",
                      "maxLength": 280
                    },
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid payload or unknown field",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired or revoked credential",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Permission denied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Dates conflict with another city, or the record changed concurrently. Read error to distinguish. Correct dates only for a city conflict; a write-only agent must ask the owner to inspect a concurrent change before retrying updates.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Request body exceeds the accepted size.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Use Content-Type: application/json.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "operationId": "createPrivateStay"
      }
    },
    "/api/plans/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "put": {
        "summary": "Update private stay (plans:write)",
        "security": [
          {
            "agentBearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "city",
                  "start",
                  "end",
                  "status"
                ],
                "properties": {
                  "city": {
                    "type": "string",
                    "description": "ID from /api/cities"
                  },
                  "start": {
                    "type": "string",
                    "format": "date",
                    "description": "Destination-local calendar date, inclusive. Allowed range 2000-01-01 through 2100-12-31. End must be on/after start; different cities cannot overlap on any inclusive day."
                  },
                  "end": {
                    "type": "string",
                    "format": "date",
                    "description": "Destination-local calendar date, inclusive. Allowed range 2000-01-01 through 2100-12-31. End must be on/after start; different cities cannot overlap on any inclusive day."
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "tentative",
                      "confirmed"
                    ]
                  },
                  "visibility": {
                    "type": "string",
                    "enum": [
                      "private"
                    ],
                    "default": "private"
                  },
                  "note": {
                    "type": "string",
                    "maxLength": 280
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Operation completed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid payload or unknown field",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired or revoked credential",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Permission denied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Dates conflict with another city, or the record changed concurrently. Read error to distinguish. Correct dates only for a city conflict; a write-only agent must ask the owner to inspect a concurrent change before retrying updates.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No plan with this ID belongs to the credential owner.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Request body exceeds the accepted size.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Use Content-Type: application/json.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "operationId": "updatePrivateStay",
        "description": "Send city, start, end and status. Omitted visibility defaults to private. Omitted note preserves the existing private note; an empty note clears it."
      },
      "delete": {
        "summary": "Delete owner-authorized private stay (plans:write)",
        "security": [
          {
            "agentBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Operation completed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired or revoked credential",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Permission denied",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Dates conflict with another city, or the record changed concurrently. Read error to distinguish. Correct dates only for a city conflict; a write-only agent must ask the owner to inspect a concurrent change before retrying updates.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No plan with this ID belongs to the credential owner.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "operationId": "deletePrivateStay"
      }
    }
  }
}
