{
  "openapi": "3.1.0",
  "info": {
    "title": "Grover Tree Service: tree requests",
    "version": "1.0.0",
    "description": "Send Grover Tree Service photos of a person's trees and what they want done. Grover reviews it, usually by the next business day, and texts a rough estimate; an arborist then visits for a written proposal. A request made here is held until the person replies YES to one text sent to their cell: an assistant can fill it in, but only the person can agree to it. Use your person's real cell and service address, and their own words.",
    "contact": {
      "name": "Grover Tree Service",
      "url": "https://trees.groverlandscapeservices.com/trees"
    }
  },
  "servers": [
    {
      "url": "https://trees.groverlandscapeservices.com"
    }
  ],
  "paths": {
    "/api/trees/requests": {
      "post": {
        "operationId": "createTreeRequest",
        "summary": "Send a tree request (it waits for the person's YES text).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "cell",
                  "address"
                ],
                "properties": {
                  "cell": {
                    "type": "string",
                    "description": "The person's US cell, any format. The YES text goes here."
                  },
                  "address": {
                    "type": "string",
                    "minLength": 5,
                    "maxLength": 300,
                    "description": "Where the trees are."
                  },
                  "name": {
                    "type": "string",
                    "maxLength": 120
                  },
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 5000,
                    "description": "What they're looking for, in their words."
                  },
                  "mode": {
                    "type": "string",
                    "enum": [
                      "myself",
                      "talk_to_arborist"
                    ],
                    "description": "Decide from the estimate, or talk it over with an arborist first."
                  },
                  "language": {
                    "type": "string",
                    "enum": [
                      "en",
                      "es"
                    ]
                  },
                  "emergency": {
                    "type": "boolean",
                    "description": "A tree down or about to fall. For danger now, call 911; for power lines, PG&E."
                  },
                  "relationship": {
                    "type": "string",
                    "enum": [
                      "own",
                      "rent",
                      "manage"
                    ]
                  },
                  "preferred_contact": {
                    "type": "string",
                    "enum": [
                      "text",
                      "call",
                      "email"
                    ]
                  },
                  "fields": {
                    "type": "object",
                    "properties": {
                      "job": {
                        "type": "string",
                        "enum": [
                          "prune",
                          "removal",
                          "removal_stump",
                          "stump",
                          "prune_and_removal",
                          "health",
                          "unsure"
                        ]
                      },
                      "how_soon": {
                        "type": "string",
                        "enum": [
                          "asap",
                          "month",
                          "flexible"
                        ]
                      },
                      "near_house": {
                        "type": "string",
                        "enum": [
                          "yes",
                          "no",
                          "unsure"
                        ]
                      },
                      "power_lines": {
                        "type": "string",
                        "enum": [
                          "yes",
                          "no",
                          "unsure"
                        ]
                      },
                      "trees": {
                        "type": "string",
                        "enum": [
                          "1",
                          "2-3",
                          "4+",
                          "unsure"
                        ]
                      },
                      "size": {
                        "type": "string",
                        "enum": [
                          "small",
                          "medium",
                          "large",
                          "unsure"
                        ]
                      },
                      "storm": {
                        "type": "string",
                        "enum": [
                          "yes",
                          "no"
                        ]
                      },
                      "range": {
                        "type": "string",
                        "description": "Low and high in cents, e.g. 75000-150000."
                      },
                      "access": {
                        "type": "string",
                        "enum": [
                          "front",
                          "back_open",
                          "gate"
                        ]
                      },
                      "city_tree": {
                        "type": "string",
                        "enum": [
                          "yes",
                          "no",
                          "unsure"
                        ]
                      },
                      "permit_help": {
                        "type": "string",
                        "enum": [
                          "yes",
                          "no"
                        ]
                      },
                      "busy_road": {
                        "type": "string",
                        "enum": [
                          "yes",
                          "no",
                          "unsure"
                        ]
                      }
                    },
                    "additionalProperties": false
                  },
                  "photo_urls": {
                    "type": "array",
                    "maxItems": 10,
                    "items": {
                      "type": "string",
                      "format": "uri"
                    },
                    "description": "Public https links to photos (image/jpeg, image/png, image/webp, image/heic, image/heif), fetched once."
                  },
                  "agent_name": {
                    "type": "string",
                    "maxLength": 80,
                    "description": "Your assistant's name; the YES text says who filled it in."
                  },
                  "src": {
                    "type": "string"
                  },
                  "utm_source": {
                    "type": "string"
                  },
                  "utm_medium": {
                    "type": "string"
                  },
                  "utm_campaign": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Made. Keep the token: it is the only key to this request.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "string",
                          "enum": [
                            "draft",
                            "awaiting_customer_yes",
                            "new",
                            "reviewing",
                            "visit_booked",
                            "closed"
                          ]
                        },
                        "waiting_for_customer_yes": {
                          "type": "boolean"
                        },
                        "language": {
                          "type": "string",
                          "enum": [
                            "en",
                            "es"
                          ]
                        },
                        "address": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "name": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "email": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "mode": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "enum": [
                            "myself",
                            "talk_to_arborist",
                            null
                          ]
                        },
                        "emergency": {
                          "type": "boolean"
                        },
                        "fields": {
                          "type": "object"
                        },
                        "photos": {
                          "type": "integer"
                        },
                        "voice_note": {
                          "type": "boolean"
                        },
                        "submitted_at": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "date-time"
                        },
                        "expires_at": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    },
                    {
                      "type": "object",
                      "properties": {
                        "token": {
                          "type": "string"
                        },
                        "link": {
                          "type": "string",
                          "format": "uri"
                        },
                        "photo_problems": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "url": {
                                "type": "string"
                              },
                              "error": {
                                "type": "string"
                              }
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "422": {
            "description": "A problem, by key: cell, address, email, name, tooLong, photo_url, expired, sent, tooMany, photoType, photoMax, server.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "429": {
            "description": "A problem, by key: cell, address, email, name, tooLong, photo_url, expired, sent, tooMany, photoType, photoMax, server.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/trees/requests/{token}": {
      "get": {
        "operationId": "getTreeRequest",
        "summary": "Where a request stands.",
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{48}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The request.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "draft",
                        "awaiting_customer_yes",
                        "new",
                        "reviewing",
                        "visit_booked",
                        "closed"
                      ]
                    },
                    "waiting_for_customer_yes": {
                      "type": "boolean"
                    },
                    "language": {
                      "type": "string",
                      "enum": [
                        "en",
                        "es"
                      ]
                    },
                    "address": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "name": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "email": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "description": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "mode": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "enum": [
                        "myself",
                        "talk_to_arborist",
                        null
                      ]
                    },
                    "emergency": {
                      "type": "boolean"
                    },
                    "fields": {
                      "type": "object"
                    },
                    "photos": {
                      "type": "integer"
                    },
                    "voice_note": {
                      "type": "boolean"
                    },
                    "submitted_at": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "date-time"
                    },
                    "expires_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "A problem, by key: cell, address, email, name, tooLong, photo_url, expired, sent, tooMany, photoType, photoMax, server.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/trees/requests/{token}/photos": {
      "post": {
        "operationId": "addTreeRequestPhoto",
        "summary": "Add a photo (at most 10): JSON {\"url\": \"https://...\"}, a multipart \"photo\" file, or the image bytes.",
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{48}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url"
                ],
                "properties": {
                  "url": {
                    "type": "string",
                    "format": "uri"
                  }
                }
              }
            },
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "photo": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            },
            "image/jpeg": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Added.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "A problem, by key: cell, address, email, name, tooLong, photo_url, expired, sent, tooMany, photoType, photoMax, server.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "409": {
            "description": "A problem, by key: cell, address, email, name, tooLong, photo_url, expired, sent, tooMany, photoType, photoMax, server.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "415": {
            "description": "A problem, by key: cell, address, email, name, tooLong, photo_url, expired, sent, tooMany, photoType, photoMax, server.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "429": {
            "description": "A problem, by key: cell, address, email, name, tooLong, photo_url, expired, sent, tooMany, photoType, photoMax, server.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    }
  }
}