{
  "openapi": "3.1.0",
  "info": {
    "title": "Geo Insights Marketing API",
    "version": "1.0.0",
    "description": "Public API for the Geo Insights marketing website. Provides contact form submission and newsletter signup endpoints.",
    "contact": {
      "name": "Geo Insights",
      "email": "hello@geo-insights.nl",
      "url": "https://geo-insights.nl"
    },
    "license": {
      "name": "Proprietary"
    }
  },
  "servers": [
    {
      "url": "https://geo-insights.nl",
      "description": "Production"
    }
  ],
  "paths": {
    "/api/contact": {
      "post": {
        "operationId": "submitContactForm",
        "summary": "Submit a contact form inquiry",
        "description": "Sends a contact form submission to the Geo Insights team via email. Rate limited to 5 requests per 10 minutes per IP address.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContactRequest"
              },
              "example": {
                "name": "Jan de Vries",
                "organization": "Gemeente Rotterdam",
                "email": "j.devries@rotterdam.nl",
                "topic": "pilot",
                "message": "Wij zijn geïnteresseerd in een pilot voor klimaatadaptatie in onze wijk."
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Message sent successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SuccessResponse"
                }
              }
            }
          },
          "400": {
            "description": "Validation error — missing or invalid fields",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "examples": {
                  "missingFields": {
                    "value": {
                      "error": "MISSING_REQUIRED_FIELDS",
                      "message": "Missing required fields",
                      "resolution": "Provide name, organization, email and message in the JSON body."
                    }
                  },
                  "invalidEmail": {
                    "value": {
                      "error": "INVALID_EMAIL",
                      "message": "Invalid email",
                      "resolution": "Provide a valid email address in the format user@domain.tld."
                    }
                  }
                }
              }
            }
          },
          "405": {
            "description": "Method not allowed — only POST is accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "headers": {
              "Retry-After": {
                "schema": { "type": "integer" },
                "description": "Seconds until the rate limit resets"
              },
              "RateLimit-Limit": {
                "schema": { "type": "integer" },
                "description": "Maximum requests allowed in the window"
              },
              "RateLimit-Remaining": {
                "schema": { "type": "integer" },
                "description": "Requests remaining in the current window"
              },
              "RateLimit-Reset": {
                "schema": { "type": "integer" },
                "description": "Seconds until the current window resets"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/newsletter": {
      "post": {
        "operationId": "subscribeNewsletter",
        "summary": "Subscribe to pilot update emails",
        "description": "Adds or updates a subscriber in the Geo Insights Mailchimp audience. Rate limited to 10 requests per 10 minutes per IP address.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewsletterRequest"
              },
              "example": {
                "email": "j.devries@rotterdam.nl",
                "firstName": "Jan",
                "lastName": "de Vries"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Subscribed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SuccessResponse"
                }
              }
            }
          },
          "400": {
            "description": "Validation error — missing or invalid email",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "405": {
            "description": "Method not allowed — only POST is accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "headers": {
              "Retry-After": {
                "schema": { "type": "integer" },
                "description": "Seconds until the rate limit resets"
              },
              "RateLimit-Limit": {
                "schema": { "type": "integer" },
                "description": "Maximum requests allowed in the window"
              },
              "RateLimit-Remaining": {
                "schema": { "type": "integer" },
                "description": "Requests remaining in the current window"
              },
              "RateLimit-Reset": {
                "schema": { "type": "integer" },
                "description": "Seconds until the current window resets"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "502": {
            "description": "Upstream error from Mailchimp",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ContactRequest": {
        "type": "object",
        "required": ["name", "organization", "email", "message"],
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 200,
            "description": "Full name of the person submitting the form"
          },
          "organization": {
            "type": "string",
            "maxLength": 200,
            "description": "Name of the municipality, water board or organization"
          },
          "email": {
            "type": "string",
            "format": "email",
            "description": "Contact email address"
          },
          "topic": {
            "type": "string",
            "description": "Optional topic or subject of the inquiry"
          },
          "message": {
            "type": "string",
            "maxLength": 5000,
            "description": "The message body"
          }
        }
      },
      "NewsletterRequest": {
        "type": "object",
        "required": ["email"],
        "properties": {
          "email": {
            "type": "string",
            "format": "email",
            "description": "Email address to subscribe"
          },
          "firstName": {
            "type": "string",
            "maxLength": 80,
            "description": "Subscriber first name (optional)"
          },
          "lastName": {
            "type": "string",
            "maxLength": 80,
            "description": "Subscriber last name (optional)"
          }
        }
      },
      "SuccessResponse": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "const": true
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["error", "message"],
        "properties": {
          "error": {
            "type": "string",
            "description": "Machine-readable error code (e.g. MISSING_REQUIRED_FIELDS, INVALID_EMAIL, RATE_LIMITED)"
          },
          "message": {
            "type": "string",
            "description": "Human-readable error description"
          },
          "resolution": {
            "type": "string",
            "description": "Suggested action to resolve the error"
          }
        }
      }
    }
  }
}
