class Api::WikiController < ApiController
  resource_description do
    short "Wiki pages"
  end

  api :GET, "/api/wiki/pages", "List wiki pages filtered by tag"
  param :tag, String, required: false, desc: "Filter by tag (blog, howto, engine)"
  param :limit, :number, required: false, desc: "Limit number of results"
  param :body, String, required: false, desc: "Include body content (1 = yes)"
  returns code: 200, desc: "Wiki pages response" do
    property :tag, String, desc: "Applied tag filter"
    property :count, Integer, desc: "Number of pages returned"
    property :pages, Array, desc: "Array of wiki pages" do
      property :id, String, desc: "Page ID"
      property :path, String, desc: "Page path"
      property :title, String, desc: "Page title"
      property :description, String, desc: "Short description"
      property :createdAt, String, desc: "Created date (ISO 8601)"
      property :updatedAt, String, desc: "Updated date (ISO 8601)"
      property :locale, String, desc: "Locale code"
      property :route, String, desc: "URL slug"
      property :tags, Array, of: String, desc: "Tags"
      property :repo, String, desc: "Git repository URL (from page metadata, engines)"
      property :render, String, desc: "Rendered HTML content"
      property :content, String, desc: "Raw markdown content"
    end
    property :error, String, desc: "Error message (null on success)"
  end
  # GET /api/wiki/pages?tag=blog|howto[&limit=30][&body=1]
  def index
    render json: WikiService.new.index(
      tag:   params[:tag],
      limit: params[:limit],
      body:  params[:body]
    )
  end
end
