{
  "openapi": "3.0.3",
  "info": {
    "title": "Campnow — CMS & FAQ API",
    "version": "1.0.0",
    "description": "Public and Admin endpoints for CMS pages and FAQs."
  },
  "servers": [
    {
      "url": "{{baseUrl}}",
      "description": "Base URL (set in Apidog environment)"
    }
  ],
  "tags": [
    { "name": "Public / CMS",  "description": "Public read-only CMS endpoints" },
    { "name": "Public / FAQ",  "description": "Public read-only FAQ endpoints" },
    { "name": "Admin / CMS",   "description": "Admin CMS management (auth required)" },
    { "name": "Admin / FAQ",   "description": "Admin FAQ management (auth required)" }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    },
    "schemas": {
      "CmsPagePublic": {
        "type": "object",
        "properties": {
          "id":      { "type": "string", "example": "664a1f2e3c4b5a6d7e8f9012" },
          "slug":    { "type": "string", "enum": ["imprint", "agb", "privacy-policy"] },
          "title":   { "type": "string", "example": "Impressum" },
          "content": { "type": "string", "example": "<p>Content here…</p>" }
        }
      },
      "CmsPageAdmin": {
        "type": "object",
        "properties": {
          "id":         { "type": "string" },
          "slug":       { "type": "string", "enum": ["imprint", "agb", "privacy-policy"] },
          "title_en":   { "type": "string" },
          "title_de":   { "type": "string" },
          "content_en": { "type": "string" },
          "content_de": { "type": "string" },
          "isActive":   { "type": "boolean" },
          "createdAt":  { "type": "string", "format": "date-time" },
          "updatedAt":  { "type": "string", "format": "date-time" }
        }
      },
      "FaqPublic": {
        "type": "object",
        "properties": {
          "id":       { "type": "string" },
          "audience": { "type": "string", "enum": ["general", "generalAudience", "campsiteOwner", "campsite"] },
          "question": { "type": "string" },
          "answer":   { "type": "string" },
          "order":    { "type": "integer" }
        }
      },
      "FaqAdmin": {
        "type": "object",
        "properties": {
          "id":          { "type": "string" },
          "audience":    { "type": "string", "enum": ["general", "generalAudience", "campsiteOwner", "campsite"] },
          "question_en": { "type": "string" },
          "question_de": { "type": "string" },
          "answer_en":   { "type": "string" },
          "answer_de":   { "type": "string" },
          "order":       { "type": "integer" },
          "campsiteId":  { "type": "string", "nullable": true },
          "isActive":    { "type": "boolean" },
          "createdAt":   { "type": "string", "format": "date-time" },
          "updatedAt":   { "type": "string", "format": "date-time" }
        }
      },
      "SuccessResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "example": true },
          "message": { "type": "string" },
          "data":    { }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "example": false },
          "message": { "type": "string" }
        }
      },
      "ValidationErrorResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "example": false },
          "message": { "type": "string", "example": "Validation failed" },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "field":   { "type": "string" },
                "message": { "type": "string" }
              }
            }
          }
        }
      }
    }
  },

  "paths": {

    "/api/cms": {
      "get": {
        "tags": ["Public / CMS"],
        "summary": "List all active CMS pages",
        "operationId": "publicGetCmsPages",
        "parameters": [
          {
            "name": "lang",
            "in": "query",
            "required": false,
            "schema": { "type": "string", "enum": ["en", "de"], "default": "en" },
            "description": "Language for title/content resolution"
          }
        ],
        "responses": {
          "200": {
            "description": "CMS pages retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": { "$ref": "#/components/schemas/CmsPagePublic" }
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },

    "/api/cms/{slug}": {
      "get": {
        "tags": ["Public / CMS"],
        "summary": "Get CMS page by slug",
        "operationId": "publicGetCmsPageBySlug",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": { "type": "string", "enum": ["imprint", "agb", "privacy-policy"] }
          },
          {
            "name": "lang",
            "in": "query",
            "required": false,
            "schema": { "type": "string", "enum": ["en", "de"], "default": "en" }
          }
        ],
        "responses": {
          "200": {
            "description": "CMS page retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "properties": {
                        "data": { "$ref": "#/components/schemas/CmsPagePublic" }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "CMS page not found",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },

    "/api/faq": {
      "get": {
        "tags": ["Public / FAQ"],
        "summary": "List active FAQs",
        "operationId": "publicGetFaqs",
        "parameters": [
          {
            "name": "audience",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": ["general", "generalAudience", "campsiteOwner", "campsite"]
            }
          },
          {
            "name": "lang",
            "in": "query",
            "required": false,
            "schema": { "type": "string", "enum": ["en", "de"], "default": "en" }
          },
          {
            "name": "campsiteId",
            "in": "query",
            "required": false,
            "schema": { "type": "string" },
            "description": "Required only when audience=campsite"
          }
        ],
        "responses": {
          "200": {
            "description": "FAQs retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": { "$ref": "#/components/schemas/FaqPublic" }
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },

    "/admin/cms": {
      "get": {
        "tags": ["Admin / CMS"],
        "summary": "List all CMS pages (active + inactive)",
        "operationId": "adminGetCmsPages",
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": {
            "description": "CMS pages retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": { "$ref": "#/components/schemas/CmsPageAdmin" }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": { "description": "Unauthorized" }
        }
      }
    },

    "/admin/cms/{id}": {
      "get": {
        "tags": ["Admin / CMS"],
        "summary": "Get single CMS page by ID",
        "operationId": "adminGetCmsPage",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "CMS page retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    { "properties": { "data": { "$ref": "#/components/schemas/CmsPageAdmin" } } }
                  ]
                }
              }
            }
          },
          "404": { "description": "CMS page not found" }
        }
      },
      "put": {
        "tags": ["Admin / CMS"],
        "summary": "Update CMS page content (slug is immutable)",
        "operationId": "adminUpdateCmsPage",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "minProperties": 1,
                "properties": {
                  "title_en":   { "type": "string", "maxLength": 200, "example": "Imprint" },
                  "title_de":   { "type": "string", "maxLength": 200, "example": "Impressum" },
                  "content_en": { "type": "string", "example": "<p>English content</p>" },
                  "content_de": { "type": "string", "example": "<p>Deutscher Inhalt</p>" },
                  "isActive":   { "type": "boolean" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "CMS page updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    { "properties": { "data": { "$ref": "#/components/schemas/CmsPageAdmin" } } }
                  ]
                }
              }
            }
          },
          "404": { "description": "CMS page not found" },
          "422": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ValidationErrorResponse" }
              }
            }
          }
        }
      },
      "delete": {
        "tags": ["Admin / CMS"],
        "summary": "Soft-delete CMS page (sets isActive=false)",
        "operationId": "adminDeleteCmsPage",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "CMS page deactivated successfully" },
          "404": { "description": "CMS page not found" }
        }
      }
    },

    "/admin/faq": {
      "get": {
        "tags": ["Admin / FAQ"],
        "summary": "List FAQs (paginated, filterable)",
        "operationId": "adminGetFaqs",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "name": "audience",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": ["general", "generalAudience", "campsiteOwner", "campsite"]
            }
          },
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": { "type": "integer", "minimum": 1, "default": 1 }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": { "type": "integer", "minimum": 1, "maximum": 250, "default": 50 }
          },
          {
            "name": "search",
            "in": "query",
            "required": false,
            "schema": { "type": "string", "maxLength": 200 }
          },
          {
            "name": "campsiteId",
            "in": "query",
            "required": false,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "FAQs retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "data": { "type": "array", "items": { "$ref": "#/components/schemas/FaqAdmin" } },
                            "meta": {
                              "type": "object",
                              "properties": {
                                "page":       { "type": "integer" },
                                "perPage":    { "type": "integer" },
                                "total":      { "type": "integer" },
                                "totalPages": { "type": "integer" }
                              }
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": ["Admin / FAQ"],
        "summary": "Create a new FAQ",
        "operationId": "adminCreateFaq",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["audience", "question_en", "question_de", "answer_en", "answer_de"],
                "properties": {
                  "audience": {
                    "type": "string",
                    "enum": ["general", "generalAudience", "campsiteOwner", "campsite"]
                  },
                  "question_en": { "type": "string", "maxLength": 500, "example": "How do I book?" },
                  "question_de": { "type": "string", "maxLength": 500, "example": "Wie buche ich?" },
                  "answer_en":   { "type": "string", "example": "Click the Book button." },
                  "answer_de":   { "type": "string", "example": "Klicken Sie auf Buchen." },
                  "order":       { "type": "integer", "minimum": 0 },
                  "campsiteId":  { "type": "string", "nullable": true, "description": "Required when audience=campsite" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "FAQ created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    { "properties": { "data": { "$ref": "#/components/schemas/FaqAdmin" } } }
                  ]
                }
              }
            }
          },
          "422": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ValidationErrorResponse" }
              }
            }
          }
        }
      }
    },

    "/admin/faq/{id}": {
      "get": {
        "tags": ["Admin / FAQ"],
        "summary": "Get single FAQ by ID",
        "operationId": "adminGetFaq",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "FAQ retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    { "properties": { "data": { "$ref": "#/components/schemas/FaqAdmin" } } }
                  ]
                }
              }
            }
          },
          "404": { "description": "FAQ not found" }
        }
      },
      "patch": {
        "tags": ["Admin / FAQ"],
        "summary": "Partial update FAQ",
        "operationId": "adminUpdateFaq",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "minProperties": 1,
                "properties": {
                  "audience": {
                    "type": "string",
                    "enum": ["general", "generalAudience", "campsiteOwner", "campsite"]
                  },
                  "question_en": { "type": "string", "maxLength": 500 },
                  "question_de": { "type": "string", "maxLength": 500 },
                  "answer_en":   { "type": "string" },
                  "answer_de":   { "type": "string" },
                  "order":       { "type": "integer", "minimum": 0 },
                  "campsiteId":  { "type": "string", "nullable": true },
                  "isActive":    { "type": "boolean" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "FAQ updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    { "properties": { "data": { "$ref": "#/components/schemas/FaqAdmin" } } }
                  ]
                }
              }
            }
          },
          "404": { "description": "FAQ not found" },
          "422": { "description": "Validation error" }
        }
      },
      "delete": {
        "tags": ["Admin / FAQ"],
        "summary": "Hard delete FAQ",
        "operationId": "adminDeleteFaq",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "FAQ deleted successfully" },
          "404": { "description": "FAQ not found" }
        }
      }
    },

    "/admin/faq/{id}/toggle-status": {
      "patch": {
        "tags": ["Admin / FAQ"],
        "summary": "Toggle FAQ active/inactive status",
        "operationId": "adminToggleFaqStatus",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "FAQ status toggled",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    { "properties": { "data": { "$ref": "#/components/schemas/FaqAdmin" } } }
                  ]
                }
              }
            }
          },
          "404": { "description": "FAQ not found" }
        }
      }
    }

  }
}
