{
  "openapi": "3.1.0",
  "info": {
    "title": "See New Zealand Public API",
    "version": "1.0.0",
    "description": "Public, anonymous endpoints for discovering See New Zealand publishers and sending user-authorised enquiries."
  },
  "servers": [
    {
      "url": "https://seenewzealand.co.nz"
    }
  ],
  "paths": {
    "/api/v1/publishers/{slug}": {
      "get": {
        "operationId": "getPublisher",
        "summary": "Get a publisher and its public content",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-z0-9-]{1,160}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Publisher data, content and enquiry capability",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PublisherResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/v1/publishers/{slug}/enquiries": {
      "post": {
        "operationId": "submitPublisherEnquiry",
        "summary": "Send an enquiry to a publisher",
        "description": "Send only when the named person has asked the agent to contact this publisher. No login, cookie, CSRF token or API key is required. Reuse the same idempotency_key when retrying an uncertain request.",
        "security": [],
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-z0-9-]{1,160}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EnquiryRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The enquiry was accepted or an idempotent retry returned the original reference",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EnquiryResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "EnquiryRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "email",
          "subject",
          "message",
          "consent"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 2,
            "maxLength": 120
          },
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 254
          },
          "organisation": {
            "type": "string",
            "maxLength": 160
          },
          "enquiry_type": {
            "type": "string",
            "enum": [
              "general",
              "media",
              "partnership",
              "booking",
              "other"
            ],
            "default": "general"
          },
          "subject": {
            "type": "string",
            "minLength": 3,
            "maxLength": 160
          },
          "message": {
            "type": "string",
            "minLength": 10,
            "maxLength": 5000
          },
          "consent": {
            "type": "boolean",
            "const": true,
            "description": "Confirms that the named person authorises the publisher to use these details to respond."
          },
          "idempotency_key": {
            "type": "string",
            "format": "uuid",
            "description": "A caller-generated UUID. Reuse it only when retrying the same enquiry."
          }
        }
      },
      "EnquiryResponse": {
        "type": "object",
        "required": [
          "api_version",
          "generated_at",
          "data"
        ],
        "properties": {
          "api_version": {
            "type": "string",
            "const": "v1"
          },
          "generated_at": {
            "type": "string",
            "format": "date-time"
          },
          "data": {
            "type": "object",
            "required": [
              "enquiry_id",
              "status",
              "publisher"
            ],
            "properties": {
              "enquiry_id": {
                "type": "string",
                "format": "uuid"
              },
              "status": {
                "type": "string",
                "const": "received"
              },
              "publisher": {
                "type": "object",
                "required": [
                  "slug",
                  "name"
                ],
                "properties": {
                  "slug": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      },
      "PublisherResponse": {
        "type": "object",
        "properties": {
          "api_version": {
            "type": "string"
          },
          "generated_at": {
            "type": "string",
            "format": "date-time"
          },
          "data": {
            "type": "object",
            "properties": {
              "slug": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "contact_url": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "uri"
              },
              "enquiry_api_url": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "uri"
              },
              "enquiry_types": {
                "type": [
                  "object",
                  "null"
                ]
              },
              "openapi_url": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "api_version": {
            "type": "string"
          },
          "generated_at": {
            "type": "string",
            "format": "date-time"
          },
          "error": {
            "type": "object",
            "properties": {
              "status": {
                "type": "integer"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "responses": {
      "NotFound": {
        "description": "Publisher not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "ValidationError": {
        "description": "The JSON request failed validation or the publisher is not accepting enquiries",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Too many requests. Respect the Retry-After response header.",
        "headers": {
          "Retry-After": {
            "schema": {
              "type": "integer"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      }
    }
  }
}
