{
  "openapi": "3.0.0",
  "info": {
    "title": "PondLinerCalc API",
    "version": "1.0.0",
    "description": "API for AI agents to load and save pond designs."
  },
  "servers": [
    {
      "url": "https://pondlinercalc.com"
    }
  ],
  "paths": {
    "/api.php": {
      "get": {
        "summary": "Load a saved project",
        "description": "Loads a saved project by its short hash.",
        "parameters": [
          {
            "name": "action",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": ["load"]
            }
          },
          {
            "name": "hash",
            "in": "query",
            "required": true,
            "description": "The 6-character alphanumeric hash of the project (e.g., abc1234).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful operation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProjectData"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Save a new project",
        "description": "Saves a new pond design and returns a shareable shortlink.",
        "parameters": [
          {
            "name": "action",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": ["save"]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProjectData"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Project successfully saved",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "success"
                    },
                    "hash": {
                      "type": "string",
                      "example": "a1b2c3"
                    },
                    "url": {
                      "type": "string",
                      "example": "https://pondlinercalc.com/a1b2c3"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ProjectData": {
        "type": "object",
        "properties": {
          "version": {
            "type": "string",
            "example": "2.0"
          },
          "inputs": {
            "type": "object",
            "properties": {
              "unit": {
                "type": "string",
                "enum": ["metric", "imperial"],
                "example": "metric"
              },
              "maxDepth": {
                "type": "string",
                "example": "1.5"
              },
              "avgDepth": {
                "type": "string",
                "example": "1.0"
              },
              "wallHeight": {
                "type": "string",
                "example": "0"
              },
              "linerCost": {
                "type": "string",
                "example": "15.00"
              }
            }
          },
          "state": {
            "type": "object",
            "properties": {
              "pondPoints": {
                "type": "array",
                "description": "Array of 2D coordinates representing the top-down perimeter of the pond.",
                "items": {
                  "type": "object",
                  "properties": {
                    "x": { "type": "number" },
                    "y": { "type": "number" }
                  }
                }
              },
              "depthStrokes": {
                "type": "array",
                "description": "Array of step terraces inside the pond.",
                "items": {
                  "type": "object",
                  "properties": {
                    "depth": { "type": "number" },
                    "width": { "type": "number" },
                    "points": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "x": { "type": "number" },
                          "y": { "type": "number" }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "results": {
            "type": "object",
            "description": "Pre-calculated results (Read-Only. Only present on load, not required for save)",
            "properties": {
              "linerDimensions": { "type": "string" },
              "linerArea": { "type": "string" },
              "estimatedCost": { "type": "string" },
              "waterVolume": { "type": "string" },
              "pumpTurnover": { "type": "string" },
              "fishKoi": { "type": "string" }
            }
          }
        }
      }
    }
  }
}
