{
  "openapi": "3.1.0",
  "info": {
    "title": "Generator Landing Reklama API",
    "description": "API-first architecture dla platformy do generowania reklam i landing pages.\n\n## Autentykacja\n\nAPI wspiera dwa rodzaje autentykacji:\n- **Session** - dla frontendu Livewire/web\n- **Bearer Token** (Sanctum) - dla zewnętrznych integracji\n\n## Kontekst workspace\n\nWiększość endpointów wymaga kontekstu workspace. Przekaż go przez header:\n```\nX-Workspace: {workspace_id}\n```\n\n## Rate Limiting\n\nAPI stosuje rate limiting:\n- Login: 5 prób/minutę per IP\n- Register: 3 próby/minutę per IP\n- AI Generation: 20 żądań/minutę per workspace\n- Image Generation: 10 żądań/minutę per workspace\n- Drive Upload: 30 żądań/minutę per workspace\n",
    "version": "1.0.0",
    "contact": {
      "name": "API Support",
      "email": "support@example.com"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://example.com/license"
    }
  },
  "servers": [
    {
      "url": "https://api.example.com/api/v1",
      "description": "Production server"
    },
    {
      "url": "https://staging-api.example.com/api/v1",
      "description": "Staging server"
    },
    {
      "url": "http://localhost/api/v1",
      "description": "Local development"
    }
  ],
  "tags": [
    {
      "name": "Auth",
      "description": "Autentykacja i zarządzanie użytkownikami"
    },
    {
      "name": "Workspaces",
      "description": "Zarządzanie workspace'ami"
    },
    {
      "name": "Drive",
      "description": "Zarządzanie plikami i folderami"
    },
    {
      "name": "Drive Assets",
      "description": "Zarządzanie assetami elementów Drive"
    },
    {
      "name": "Templates",
      "description": "Zarządzanie szablonami treści"
    },
    {
      "name": "Agent",
      "description": "Konwersacje z agentem AI i zarządzanie wiadomościami"
    },
    {
      "name": "Website Pages",
      "description": "Zarządzanie stronami w projektach website"
    },
    {
      "name": "Pipelines",
      "description": "Zarządzanie pipeline'ami (flow editor)"
    },
    {
      "name": "AI",
      "description": "Generowanie treści przez AI"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Sanctum Token",
        "description": "Token Sanctum uzyskany z endpointu /auth/login.\n\nPrzykład:\n```\nAuthorization: Bearer 1|abc123xyz...\n```\n"
      }
    },
    "schemas": {
      "SuccessResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "data": {
            "type": "object",
            "nullable": true
          },
          "message": {
            "type": "string",
            "nullable": true
          },
          "meta": {
            "type": "object",
            "nullable": true
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": [
          "success",
          "message"
        ],
        "properties": {
          "success": {
            "type": "boolean",
            "example": false
          },
          "message": {
            "type": "string",
            "example": "Resource not found"
          },
          "errors": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "example": {
              "email": [
                "The email field is required."
              ]
            }
          }
        }
      },
      "PaginationMeta": {
        "type": "object",
        "properties": {
          "current_page": {
            "type": "integer",
            "example": 1
          },
          "per_page": {
            "type": "integer",
            "example": 15
          },
          "total": {
            "type": "integer",
            "example": 100
          },
          "last_page": {
            "type": "integer",
            "example": 7
          },
          "from": {
            "type": "integer",
            "example": 1
          },
          "to": {
            "type": "integer",
            "example": 15
          }
        }
      },
      "User": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "example": 1
          },
          "name": {
            "type": "string",
            "example": "Jan Kowalski"
          },
          "email": {
            "type": "string",
            "format": "email",
            "example": "jan@example.com"
          },
          "avatar": {
            "type": "string",
            "nullable": true,
            "example": "https://example.com/avatar.jpg"
          },
          "current_workspace_id": {
            "type": "integer",
            "nullable": true,
            "example": 1
          },
          "current_project_id": {
            "type": "integer",
            "nullable": true,
            "example": 1
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Workspace": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "example": 1
          },
          "name": {
            "type": "string",
            "example": "Moja Firma"
          },
          "slug": {
            "type": "string",
            "example": "moja-firma"
          },
          "description": {
            "type": "string",
            "nullable": true
          },
          "credit_balance": {
            "type": "number",
            "format": "float",
            "example": 100.5
          },
          "owner_id": {
            "type": "integer",
            "example": 1
          },
          "users_count": {
            "type": "integer",
            "example": 5
          },
          "projects_count": {
            "type": "integer",
            "example": 3
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WorkspaceListItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "example": 1
          },
          "name": {
            "type": "string",
            "example": "Moja Firma"
          },
          "slug": {
            "type": "string",
            "example": "moja-firma"
          },
          "role": {
            "type": "string",
            "enum": [
              "owner",
              "admin",
              "member"
            ],
            "example": "owner"
          },
          "credit_balance": {
            "type": "number",
            "format": "float",
            "example": 100.5
          },
          "users_count": {
            "type": "integer",
            "example": 5
          },
          "projects_count": {
            "type": "integer",
            "example": 3
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "DriveItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "example": 123
          },
          "name": {
            "type": "string",
            "example": "Kampania Q1 2024"
          },
          "type": {
            "type": "string",
            "enum": [
              "folder",
              "text",
              "note",
              "document",
              "image",
              "file",
              "html",
              "css",
              "js",
              "landing_page",
              "landing_site",
              "table",
              "ad",
              "prompt",
              "list",
              "color",
              "ai_image",
              "site_analysis",
              "video",
              "font"
            ],
            "example": "folder"
          },
          "parent_id": {
            "type": "integer",
            "nullable": true,
            "example": null
          },
          "project_id": {
            "type": "integer",
            "example": 1
          },
          "content": {
            "type": "object",
            "nullable": true,
            "additionalProperties": true,
            "example": {
              "title": "Nagłówek kampanii",
              "description": "Opis kampanii reklamowej"
            }
          },
          "description": {
            "type": "string",
            "nullable": true
          },
          "file_path": {
            "type": "string",
            "nullable": true,
            "example": "drive/images/banner.jpg"
          },
          "mime_type": {
            "type": "string",
            "nullable": true,
            "example": "image/jpeg"
          },
          "file_size": {
            "type": "integer",
            "nullable": true,
            "example": 1048576
          },
          "generated_html": {
            "type": "string",
            "nullable": true
          },
          "is_published": {
            "type": "boolean",
            "example": false
          },
          "public_token": {
            "type": "string",
            "nullable": true
          },
          "is_favorite": {
            "type": "boolean",
            "example": false
          },
          "title": {
            "type": "string",
            "nullable": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "DriveItemCreate": {
        "type": "object",
        "required": [
          "name",
          "type"
        ],
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 255,
            "example": "Nowy folder"
          },
          "type": {
            "type": "string",
            "enum": [
              "folder",
              "text",
              "note",
              "document",
              "image",
              "file",
              "html",
              "css",
              "js",
              "landing_page",
              "landing_site",
              "table",
              "ad",
              "prompt",
              "list",
              "color",
              "ai_image",
              "site_analysis",
              "video",
              "font"
            ],
            "example": "folder"
          },
          "parent_id": {
            "type": "integer",
            "nullable": true,
            "example": null
          },
          "project_id": {
            "type": "integer",
            "nullable": true
          },
          "template_id": {
            "type": "integer",
            "nullable": true
          },
          "content": {
            "type": "object",
            "nullable": true,
            "additionalProperties": true
          },
          "description": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "DriveItemUpdate": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 255,
            "example": "Zaktualizowana nazwa"
          },
          "content": {
            "type": "object",
            "nullable": true,
            "additionalProperties": true
          },
          "description": {
            "type": "string",
            "nullable": true
          },
          "order": {
            "type": "integer"
          },
          "generated_html": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "Breadcrumb": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "example": 1
          },
          "name": {
            "type": "string",
            "example": "Folder główny"
          },
          "type": {
            "type": "string",
            "example": "folder"
          }
        }
      },
      "Template": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "example": 1
          },
          "name": {
            "type": "string",
            "example": "Banner reklamowy"
          },
          "code": {
            "type": "string",
            "pattern": "^[a-z0-9_]+$",
            "example": "banner_reklamowy"
          },
          "description": {
            "type": "string",
            "nullable": true,
            "example": "Szablon dla banerów reklamowych"
          },
          "type": {
            "type": "string",
            "nullable": true,
            "example": "ad"
          },
          "button_name": {
            "type": "string",
            "nullable": true,
            "example": "Utwórz banner"
          },
          "button_icon": {
            "type": "string",
            "nullable": true,
            "example": "🖼️"
          },
          "schema_definition": {
            "type": "object",
            "nullable": true,
            "properties": {
              "fields": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/TemplateField"
                }
              },
              "show_assets": {
                "type": "boolean"
              },
              "asset_ids": {
                "type": "array",
                "items": {
                  "type": "integer"
                }
              }
            }
          },
          "is_active": {
            "type": "boolean",
            "example": true
          },
          "show_in_types": {
            "type": "boolean",
            "example": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "TemplateField": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "text",
              "textarea",
              "number",
              "select",
              "boolean",
              "image",
              "color",
              "html",
              "markdown",
              "prompt",
              "rich_text"
            ],
            "example": "text"
          },
          "label": {
            "type": "string",
            "nullable": true,
            "example": "Nagłówek"
          },
          "placeholder": {
            "type": "string",
            "nullable": true,
            "example": "Wpisz nagłówek..."
          },
          "multiple": {
            "type": "boolean",
            "nullable": true
          },
          "required": {
            "type": "boolean",
            "nullable": true
          },
          "limit": {
            "type": "integer",
            "nullable": true
          },
          "options": {
            "type": "array",
            "nullable": true,
            "items": {
              "type": "string"
            }
          },
          "ai_enabled": {
            "type": "boolean",
            "nullable": true
          },
          "ai_system_prompt": {
            "type": "string",
            "nullable": true
          },
          "default_value": {
            "nullable": true
          }
        }
      },
      "TemplateCreate": {
        "type": "object",
        "required": [
          "name",
          "code"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 2,
            "maxLength": 255,
            "example": "Banner reklamowy"
          },
          "code": {
            "type": "string",
            "minLength": 2,
            "maxLength": 100,
            "pattern": "^[a-z0-9_]+$",
            "example": "banner_reklamowy"
          },
          "description": {
            "type": "string",
            "nullable": true,
            "maxLength": 2000
          },
          "type": {
            "type": "string",
            "nullable": true,
            "maxLength": 100
          },
          "button_name": {
            "type": "string",
            "nullable": true,
            "maxLength": 100
          },
          "button_icon": {
            "type": "string",
            "nullable": true,
            "maxLength": 10
          },
          "schema_definition": {
            "type": "object",
            "nullable": true
          },
          "is_active": {
            "type": "boolean"
          },
          "show_in_types": {
            "type": "boolean"
          }
        }
      },
      "AgentConversation": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "example": 42
          },
          "title": {
            "type": "string",
            "example": "Analiza strony internetowej"
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "archived",
              "closed"
            ],
            "example": "active"
          },
          "agent_definition_id": {
            "type": "integer",
            "nullable": true,
            "example": 1
          },
          "messages_count": {
            "type": "integer",
            "example": 5
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "AgentMessage": {
        "type": "object",
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "user",
              "assistant",
              "system"
            ],
            "example": "user"
          },
          "content": {
            "type": "string",
            "example": "Przeanalizuj stronę anthropic.com"
          },
          "tool_calls": {
            "type": "array",
            "nullable": true,
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string",
                  "example": "fetch_webpage"
                },
                "arguments": {
                  "type": "object"
                }
              }
            }
          }
        }
      },
      "AgentJobStatus": {
        "type": "object",
        "properties": {
          "job_id": {
            "type": "string",
            "format": "uuid",
            "example": "550e8400-e29b-41d4-a716-446655440000"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "processing",
              "completed",
              "failed"
            ],
            "example": "completed"
          },
          "progress": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100,
            "example": 100
          },
          "result": {
            "type": "object",
            "nullable": true
          },
          "error": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "WebsitePage": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "example": 1
          },
          "name": {
            "type": "string",
            "example": "Strona główna"
          },
          "slug": {
            "type": "string",
            "example": "strona-glowna"
          },
          "html": {
            "type": "string",
            "nullable": true,
            "description": "Pełny HTML strony"
          },
          "sections": {
            "type": "array",
            "nullable": true,
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "type": {
                  "type": "string"
                },
                "html": {
                  "type": "string"
                }
              }
            }
          },
          "show_in_menu": {
            "type": "boolean",
            "example": true
          },
          "order": {
            "type": "integer",
            "example": 0
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Pipeline": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "example": 1
          },
          "name": {
            "type": "string",
            "example": "Generowanie kampanii"
          },
          "description": {
            "type": "string",
            "nullable": true,
            "example": "Pipeline do automatycznego generowania materiałów kampanii"
          },
          "nodes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PipelineNode"
            }
          },
          "edges": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PipelineEdge"
            }
          },
          "viewport": {
            "type": "object",
            "properties": {
              "x": {
                "type": "number"
              },
              "y": {
                "type": "number"
              },
              "zoom": {
                "type": "number"
              }
            }
          },
          "project_id": {
            "type": "integer",
            "example": 1
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "PipelineNode": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "node_1"
          },
          "type": {
            "type": "string",
            "example": "ai_text"
          },
          "position": {
            "type": "object",
            "properties": {
              "x": {
                "type": "number"
              },
              "y": {
                "type": "number"
              }
            }
          },
          "data": {
            "type": "object",
            "additionalProperties": true,
            "description": "Dynamiczne dane specyficzne dla typu node'a"
          }
        }
      },
      "PipelineEdge": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "edge_1"
          },
          "source": {
            "type": "string",
            "example": "node_1"
          },
          "target": {
            "type": "string",
            "example": "node_2"
          },
          "sourceHandle": {
            "type": "string",
            "nullable": true
          },
          "targetHandle": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "PipelineCreate": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 255,
            "example": "Nowy pipeline"
          },
          "description": {
            "type": "string",
            "nullable": true,
            "maxLength": 2000
          },
          "nodes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PipelineNode"
            }
          },
          "edges": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PipelineEdge"
            }
          },
          "viewport": {
            "type": "object",
            "properties": {
              "x": {
                "type": "number",
                "default": 0
              },
              "y": {
                "type": "number",
                "default": 0
              },
              "zoom": {
                "type": "number",
                "default": 1
              }
            }
          }
        }
      },
      "AiTextGenerateRequest": {
        "type": "object",
        "required": [
          "prompt"
        ],
        "properties": {
          "prompt": {
            "type": "string",
            "maxLength": 10000,
            "description": "Prompt do wygenerowania tekstu",
            "example": "Napisz chwytliwy nagłówek reklamowy dla sklepu z elektroniką"
          },
          "system_prompt": {
            "type": "string",
            "maxLength": 5000,
            "nullable": true,
            "description": "System prompt definiujący kontekst AI",
            "example": "Jesteś ekspertem od marketingu cyfrowego"
          },
          "model": {
            "type": "string",
            "default": "gemini-3-pro-preview",
            "example": "gemini-3-pro-preview"
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1,
            "maximum": 8000,
            "default": 2000,
            "example": 2000
          },
          "temperature": {
            "type": "number",
            "minimum": 0,
            "maximum": 2,
            "default": 0.7,
            "example": 0.7
          }
        }
      },
      "AiTextGenerateResponse": {
        "type": "object",
        "properties": {
          "text": {
            "type": "string",
            "example": "Odkryj świat technologii w zasięgu ręki!"
          },
          "usage": {
            "type": "object",
            "nullable": true,
            "properties": {
              "prompt_tokens": {
                "type": "integer",
                "example": 25
              },
              "completion_tokens": {
                "type": "integer",
                "example": 15
              },
              "total_tokens": {
                "type": "integer",
                "example": 40
              }
            }
          }
        }
      },
      "AiImageGenerateRequest": {
        "type": "object",
        "required": [
          "prompt"
        ],
        "properties": {
          "prompt": {
            "type": "string",
            "maxLength": 5000,
            "description": "Opis obrazu do wygenerowania",
            "example": "Nowoczesny baner reklamowy dla e-commerce, minimalistyczny styl, niebieskie odcienie"
          },
          "model": {
            "type": "string",
            "nullable": true,
            "example": "nanobanana"
          },
          "size": {
            "type": "string",
            "enum": [
              "256x256",
              "512x512",
              "1024x1024"
            ],
            "nullable": true,
            "example": "1024x1024"
          },
          "style": {
            "type": "string",
            "nullable": true,
            "example": "photorealistic"
          }
        }
      },
      "AiImageGenerateResponse": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "example": "https://storage.example.com/images/generated-123.png"
          },
          "model": {
            "type": "string",
            "example": "nanobanana"
          }
        }
      },
      "AiImageAsyncResponse": {
        "type": "object",
        "properties": {
          "job_id": {
            "type": "string",
            "format": "uuid",
            "example": "550e8400-e29b-41d4-a716-446655440000"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "processing",
              "completed",
              "failed"
            ],
            "example": "pending"
          },
          "model": {
            "type": "string",
            "example": "gemini-3-pro-image-preview"
          }
        }
      },
      "AiJobStatus": {
        "type": "object",
        "properties": {
          "job_id": {
            "type": "string",
            "format": "uuid",
            "example": "550e8400-e29b-41d4-a716-446655440000"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "processing",
              "completed",
              "failed"
            ],
            "example": "completed"
          },
          "progress": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100,
            "example": 100
          },
          "stage": {
            "type": "string",
            "nullable": true,
            "example": "Generowanie zakończone"
          },
          "image_url": {
            "type": "string",
            "format": "uri",
            "nullable": true,
            "example": "https://storage.example.com/images/generated-123.png"
          },
          "error": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "AiChatRequest": {
        "type": "object",
        "required": [
          "messages"
        ],
        "properties": {
          "messages": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "required": [
                "role",
                "content"
              ],
              "properties": {
                "role": {
                  "type": "string",
                  "enum": [
                    "user",
                    "assistant",
                    "system"
                  ]
                },
                "content": {
                  "type": "string"
                }
              }
            },
            "example": [
              {
                "role": "system",
                "content": "Jesteś asystentem marketingu"
              },
              {
                "role": "user",
                "content": "Zaproponuj hasło reklamowe"
              }
            ]
          },
          "model": {
            "type": "string",
            "nullable": true,
            "example": "gemini-3-pro-preview"
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1,
            "maximum": 8000,
            "nullable": true,
            "example": 2000
          },
          "temperature": {
            "type": "number",
            "minimum": 0,
            "maximum": 2,
            "nullable": true,
            "example": 0.7
          }
        }
      },
      "AiChatResponse": {
        "type": "object",
        "properties": {
          "message": {
            "type": "object",
            "properties": {
              "role": {
                "type": "string",
                "example": "assistant"
              },
              "content": {
                "type": "string",
                "example": "Oto propozycja hasła: 'Twoja wizja, nasza technologia'"
              }
            }
          },
          "usage": {
            "type": "object",
            "nullable": true,
            "properties": {
              "prompt_tokens": {
                "type": "integer"
              },
              "completion_tokens": {
                "type": "integer"
              },
              "total_tokens": {
                "type": "integer"
              }
            }
          }
        }
      }
    },
    "parameters": {
      "WorkspaceHeader": {
        "name": "X-Workspace",
        "in": "header",
        "required": true,
        "description": "ID aktualnego workspace",
        "schema": {
          "type": "integer",
          "example": 1
        }
      },
      "ProjectHeader": {
        "name": "X-Project",
        "in": "header",
        "required": false,
        "description": "ID aktualnego projektu (opcjonalnie)",
        "schema": {
          "type": "integer",
          "example": 1
        }
      },
      "IdPath": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "ID zasobu",
        "schema": {
          "type": "integer",
          "example": 1
        }
      },
      "PageQuery": {
        "name": "page",
        "in": "query",
        "description": "Numer strony",
        "schema": {
          "type": "integer",
          "default": 1,
          "example": 1
        }
      },
      "PerPageQuery": {
        "name": "per_page",
        "in": "query",
        "description": "Liczba elementów na stronie",
        "schema": {
          "type": "integer",
          "default": 15,
          "maximum": 100,
          "example": 15
        }
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Brak autoryzacji - nieprawidłowy lub brakujący token",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "success": false,
              "message": "Unauthorized"
            }
          }
        }
      },
      "Forbidden": {
        "description": "Brak uprawnień do zasobu",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "success": false,
              "message": "Access denied"
            }
          }
        }
      },
      "NotFound": {
        "description": "Zasób nie został znaleziony",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "success": false,
              "message": "Resource not found"
            }
          }
        }
      },
      "ValidationError": {
        "description": "Błąd walidacji danych wejściowych",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "success": false,
              "message": "Validation failed",
              "errors": {
                "name": [
                  "The name field is required."
                ],
                "email": [
                  "The email must be a valid email address."
                ]
              }
            }
          }
        }
      },
      "InsufficientCredits": {
        "description": "Niewystarczająca ilość kredytów",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "success": false,
              "message": "Insufficient credits"
            }
          }
        }
      }
    }
  },
  "paths": {
    "/auth/login": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Logowanie i pobranie tokena API",
        "description": "Logowanie użytkownika i zwrócenie tokena Bearer do autoryzacji kolejnych żądań.\n\nRate limit: 5 prób/minutę per IP\n",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email",
                  "password"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "example": "user@example.com"
                  },
                  "password": {
                    "type": "string",
                    "format": "password",
                    "example": "secret123"
                  },
                  "device_name": {
                    "type": "string",
                    "description": "Nazwa urządzenia/aplikacji do identyfikacji tokena",
                    "example": "iPhone 15 Pro"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Pomyślne logowanie",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "token": {
                              "type": "string",
                              "example": "1|abc123xyz789..."
                            },
                            "token_type": {
                              "type": "string",
                              "example": "Bearer"
                            },
                            "user": {
                              "$ref": "#/components/schemas/User"
                            }
                          }
                        },
                        "message": {
                          "type": "string",
                          "example": "Login successful"
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "success": true,
                  "data": {
                    "token": "1|abc123xyz789def456...",
                    "token_type": "Bearer",
                    "user": {
                      "id": 1,
                      "name": "Jan Kowalski",
                      "email": "jan@example.com",
                      "avatar": null,
                      "current_workspace_id": 1,
                      "current_project_id": 1
                    }
                  },
                  "message": "Login successful"
                }
              }
            }
          },
          "401": {
            "description": "Nieprawidłowe dane logowania",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "success": false,
                  "message": "Invalid credentials",
                  "errors": {
                    "email": [
                      "The provided credentials are incorrect."
                    ]
                  }
                }
              }
            }
          },
          "403": {
            "description": "Konto zablokowane",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "success": false,
                  "message": "Account is blocked"
                }
              }
            }
          }
        }
      }
    },
    "/auth/register": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Rejestracja nowego użytkownika",
        "description": "Rejestracja nowego konta. Automatycznie tworzy domyślny workspace.\n\nRate limit: 3 próby/minutę per IP\n",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "email",
                  "password",
                  "password_confirmation"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "example": "Jan Kowalski"
                  },
                  "email": {
                    "type": "string",
                    "format": "email",
                    "example": "jan@example.com"
                  },
                  "password": {
                    "type": "string",
                    "format": "password",
                    "minLength": 8,
                    "example": "secretpassword123"
                  },
                  "password_confirmation": {
                    "type": "string",
                    "format": "password",
                    "example": "secretpassword123"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Użytkownik zarejestrowany",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "token": {
                              "type": "string"
                            },
                            "token_type": {
                              "type": "string"
                            },
                            "user": {
                              "$ref": "#/components/schemas/User"
                            }
                          }
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "success": true,
                  "data": {
                    "token": "1|newtoken123...",
                    "token_type": "Bearer",
                    "user": {
                      "id": 5,
                      "name": "Jan Kowalski",
                      "email": "jan@example.com",
                      "current_workspace_id": 3,
                      "current_project_id": 4
                    }
                  },
                  "message": "Registration successful"
                }
              }
            }
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/auth/logout": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Wylogowanie",
        "description": "Unieważnia aktualny token API",
        "responses": {
          "200": {
            "description": "Pomyślne wylogowanie",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": null,
                  "message": "Logged out successfully"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/auth/me": {
      "get": {
        "tags": [
          "Auth"
        ],
        "summary": "Dane zalogowanego użytkownika",
        "description": "Zwraca pełne dane aktualnie zalogowanego użytkownika wraz z workspace'ami",
        "responses": {
          "200": {
            "description": "Dane użytkownika",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": {
                    "id": 1,
                    "name": "Jan Kowalski",
                    "email": "jan@example.com",
                    "avatar": null,
                    "current_workspace_id": 1,
                    "current_project_id": 1,
                    "current_workspace": {
                      "id": 1,
                      "name": "Moja Firma",
                      "slug": "moja-firma"
                    },
                    "current_project": {
                      "id": 1,
                      "name": "Kampania Q1",
                      "slug": "kampania-q1"
                    },
                    "workspaces": [
                      {
                        "id": 1,
                        "name": "Moja Firma",
                        "slug": "moja-firma",
                        "role": "owner"
                      },
                      {
                        "id": 2,
                        "name": "Klient ABC",
                        "slug": "klient-abc",
                        "role": "member"
                      }
                    ]
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/workspaces": {
      "get": {
        "tags": [
          "Workspaces"
        ],
        "summary": "Lista workspace'ów użytkownika",
        "description": "Zwraca wszystkie workspace'y, do których użytkownik ma dostęp",
        "responses": {
          "200": {
            "description": "Lista workspace'ów",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/WorkspaceListItem"
                          }
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "success": true,
                  "data": [
                    {
                      "id": 1,
                      "name": "Moja Firma",
                      "slug": "moja-firma",
                      "role": "owner",
                      "credit_balance": 100.5,
                      "users_count": 5,
                      "projects_count": 3,
                      "created_at": "2024-01-15T10:30:00Z"
                    },
                    {
                      "id": 2,
                      "name": "Klient ABC",
                      "slug": "klient-abc",
                      "role": "member",
                      "credit_balance": 50.0,
                      "users_count": 3,
                      "projects_count": 2,
                      "created_at": "2024-02-01T14:00:00Z"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "tags": [
          "Workspaces"
        ],
        "summary": "Utwórz nowy workspace",
        "description": "Tworzy nowy workspace i opcjonalnie domyślny projekt",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 255,
                    "example": "Nowy Workspace"
                  },
                  "slug": {
                    "type": "string",
                    "maxLength": 255,
                    "example": "nowy-workspace"
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 1000,
                    "example": "Opis workspace'a"
                  },
                  "create_default_project": {
                    "type": "boolean",
                    "default": true,
                    "description": "Czy utworzyć domyślny projekt"
                  },
                  "switch_to": {
                    "type": "boolean",
                    "default": false,
                    "description": "Czy przełączyć się na nowy workspace"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Workspace utworzony",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": {
                    "id": 5,
                    "name": "Nowy Workspace",
                    "slug": "nowy-workspace",
                    "description": "Opis workspace'a",
                    "credit_balance": 0,
                    "default_project_id": 10
                  },
                  "message": "Workspace created"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/workspaces/{workspace}": {
      "get": {
        "tags": [
          "Workspaces"
        ],
        "summary": "Szczegóły workspace",
        "description": "Zwraca szczegółowe informacje o workspace",
        "parameters": [
          {
            "name": "workspace",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "example": 1
          }
        ],
        "responses": {
          "200": {
            "description": "Dane workspace",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/Workspace"
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "success": true,
                  "data": {
                    "id": 1,
                    "name": "Moja Firma",
                    "slug": "moja-firma",
                    "credit_balance": 100.5,
                    "owner_id": 1,
                    "users_count": 5,
                    "projects_count": 3,
                    "created_at": "2024-01-15T10:30:00Z",
                    "updated_at": "2024-03-01T08:00:00Z"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "put": {
        "tags": [
          "Workspaces"
        ],
        "summary": "Aktualizuj workspace",
        "description": "Aktualizuje dane workspace.\n\nWymaga roli `owner` lub `admin`.\n",
        "parameters": [
          {
            "name": "workspace",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "example": 1
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 255,
                    "example": "Zaktualizowana nazwa"
                  },
                  "slug": {
                    "type": "string",
                    "maxLength": 255,
                    "example": "zaktualizowany-slug"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Workspace zaktualizowany",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": {
                    "id": 1,
                    "name": "Zaktualizowana nazwa",
                    "slug": "zaktualizowany-slug"
                  },
                  "message": "Workspace updated"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      },
      "delete": {
        "tags": [
          "Workspaces"
        ],
        "summary": "Usuń workspace",
        "description": "Usuwa workspace i wszystkie powiązane dane.\n\n**UWAGA:** Ta operacja jest nieodwracalna!\n\nWymaga roli `owner`.\n",
        "parameters": [
          {
            "name": "workspace",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "example": 1
          }
        ],
        "responses": {
          "200": {
            "description": "Workspace usunięty",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": null,
                  "message": "Workspace deleted"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/drive": {
      "get": {
        "tags": [
          "Drive"
        ],
        "summary": "Lista elementów Drive",
        "description": "Zwraca listę elementów (plików i folderów) z Drive.\n\nWspiera filtrowanie, sortowanie i paginację.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "parent_id",
            "in": "query",
            "description": "ID folderu nadrzędnego (null = root)",
            "schema": {
              "type": "integer",
              "nullable": true
            }
          },
          {
            "name": "type",
            "in": "query",
            "description": "Filtruj po typie elementu",
            "schema": {
              "type": "string",
              "enum": [
                "folder",
                "text",
                "image",
                "video",
                "ad",
                "prompt",
                "list",
                "color"
              ]
            }
          },
          {
            "name": "types",
            "in": "query",
            "description": "Filtruj po wielu typach (tablica)",
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "name": "search",
            "in": "query",
            "description": "Szukaj po nazwie",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "favorites",
            "in": "query",
            "description": "Tylko ulubione",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "recent",
            "in": "query",
            "description": "Ostatnio używane",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "shared",
            "in": "query",
            "description": "Udostępnione",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "collection_id",
            "in": "query",
            "description": "Filtruj po kolekcji",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "sort_field",
            "in": "query",
            "description": "Pole sortowania",
            "schema": {
              "type": "string",
              "default": "created_at",
              "enum": [
                "created_at",
                "updated_at",
                "name",
                "type"
              ]
            }
          },
          {
            "name": "sort_direction",
            "in": "query",
            "description": "Kierunek sortowania",
            "schema": {
              "type": "string",
              "default": "desc",
              "enum": [
                "asc",
                "desc"
              ]
            }
          },
          {
            "name": "with_path",
            "in": "query",
            "description": "Dołącz ścieżkę do elementu",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "$ref": "#/components/parameters/PerPageQuery"
          }
        ],
        "responses": {
          "200": {
            "description": "Lista elementów",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/DriveItem"
                          }
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "success": true,
                  "data": [
                    {
                      "id": 1,
                      "name": "Kampanie 2024",
                      "type": "folder",
                      "parent_id": null,
                      "project_id": 1,
                      "is_favorite": false,
                      "created_at": "2024-01-15T10:00:00Z",
                      "updated_at": "2024-03-01T12:00:00Z"
                    },
                    {
                      "id": 2,
                      "name": "Banner główny",
                      "type": "image",
                      "parent_id": 1,
                      "project_id": 1,
                      "file_path": "drive/images/banner.jpg",
                      "mime_type": "image/jpeg",
                      "file_size": 1048576,
                      "is_favorite": true,
                      "created_at": "2024-02-01T14:00:00Z",
                      "updated_at": "2024-02-15T09:30:00Z"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "tags": [
          "Drive"
        ],
        "summary": "Utwórz nowy element",
        "description": "Tworzy nowy element w Drive (folder, dokument, itp.)",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DriveItemCreate"
              },
              "examples": {
                "folder": {
                  "summary": "Tworzenie folderu",
                  "value": {
                    "name": "Nowy folder",
                    "type": "folder",
                    "parent_id": null
                  }
                },
                "text": {
                  "summary": "Tworzenie dokumentu tekstowego",
                  "value": {
                    "name": "Notatka",
                    "type": "text",
                    "parent_id": 1,
                    "content": {
                      "body": "Treść notatki..."
                    }
                  }
                },
                "prompt": {
                  "summary": "Tworzenie prompta AI",
                  "value": {
                    "name": "Prompt reklamowy",
                    "type": "prompt",
                    "parent_id": 1,
                    "content": {
                      "prompt": "Napisz reklamę dla {{product}}",
                      "variables": [
                        "product"
                      ]
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Element utworzony",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": {
                    "id": 123,
                    "name": "Nowy folder",
                    "type": "folder",
                    "parent_id": null,
                    "project_id": 1
                  },
                  "message": "Item created"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/drive/{id}": {
      "get": {
        "tags": [
          "Drive"
        ],
        "summary": "Szczegóły elementu",
        "description": "Zwraca pełne dane elementu wraz z breadcrumbs",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "$ref": "#/components/parameters/IdPath"
          }
        ],
        "responses": {
          "200": {
            "description": "Dane elementu",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "allOf": [
                            {
                              "$ref": "#/components/schemas/DriveItem"
                            },
                            {
                              "type": "object",
                              "properties": {
                                "breadcrumbs": {
                                  "type": "array",
                                  "items": {
                                    "$ref": "#/components/schemas/Breadcrumb"
                                  }
                                },
                                "children_count": {
                                  "type": "integer"
                                }
                              }
                            }
                          ]
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "success": true,
                  "data": {
                    "id": 2,
                    "name": "Banner główny",
                    "type": "image",
                    "parent_id": 1,
                    "project_id": 1,
                    "content": null,
                    "description": "Banner reklamowy Q1 2024",
                    "file_path": "drive/images/banner.jpg",
                    "mime_type": "image/jpeg",
                    "file_size": 1048576,
                    "is_published": false,
                    "is_favorite": true,
                    "created_at": "2024-02-01T14:00:00Z",
                    "updated_at": "2024-02-15T09:30:00Z",
                    "parent": {
                      "id": 1,
                      "name": "Kampanie 2024",
                      "type": "folder"
                    },
                    "children_count": 0,
                    "breadcrumbs": [
                      {
                        "id": 1,
                        "name": "Kampanie 2024",
                        "type": "folder"
                      }
                    ]
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "put": {
        "tags": [
          "Drive"
        ],
        "summary": "Aktualizuj element",
        "description": "Aktualizuje dane elementu (nazwa, content, itp.)",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "$ref": "#/components/parameters/IdPath"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DriveItemUpdate"
              },
              "example": {
                "name": "Zaktualizowana nazwa",
                "content": {
                  "body": "Nowa treść dokumentu"
                },
                "description": "Zaktualizowany opis"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Element zaktualizowany",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": {
                    "id": 2,
                    "name": "Zaktualizowana nazwa",
                    "type": "text",
                    "content": {
                      "body": "Nowa treść dokumentu"
                    },
                    "updated_at": "2024-03-15T10:00:00Z"
                  },
                  "message": "Item updated"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      },
      "delete": {
        "tags": [
          "Drive"
        ],
        "summary": "Usuń element",
        "description": "Przenosi element do kosza (soft delete).\n\nUżyj `/drive/trash/{id}/force` aby trwale usunąć.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "$ref": "#/components/parameters/IdPath"
          }
        ],
        "responses": {
          "200": {
            "description": "Element usunięty (przeniesiony do kosza)",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": null,
                  "message": "Item deleted"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/ai/generate-text": {
      "post": {
        "tags": [
          "AI"
        ],
        "summary": "Generuj tekst przez AI",
        "description": "Synchroniczne generowanie tekstu przez model AI.\n\nRate limit: 20 żądań/minutę per workspace\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AiTextGenerateRequest"
              },
              "example": {
                "prompt": "Napisz chwytliwy nagłówek reklamowy dla sklepu z elektroniką",
                "system_prompt": "Jesteś ekspertem od marketingu cyfrowego. Pisz krótko i przekonująco.",
                "model": "gemini-3-pro-preview",
                "max_tokens": 500,
                "temperature": 0.8
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Wygenerowany tekst",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/AiTextGenerateResponse"
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "success": true,
                  "data": {
                    "text": "Odkryj świat technologii w zasięgu ręki - najnowsze gadżety w najlepszych cenach!",
                    "usage": {
                      "prompt_tokens": 45,
                      "completion_tokens": 18,
                      "total_tokens": 63
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/InsufficientCredits"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "500": {
            "description": "Błąd generowania",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "success": false,
                  "message": "AI generation failed: Model unavailable"
                }
              }
            }
          }
        }
      }
    },
    "/ai/generate-image": {
      "post": {
        "tags": [
          "AI"
        ],
        "summary": "Generuj obraz (synchronicznie)",
        "description": "Synchroniczne generowanie obrazu przez AI.\n\n**UWAGA:** Może zająć kilka sekund. Dla dłuższych operacji użyj `/ai/generate-image-async`.\n\nRate limit: 10 żądań/minutę per workspace\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AiImageGenerateRequest"
              },
              "example": {
                "prompt": "Nowoczesny baner reklamowy dla e-commerce, minimalistyczny styl, niebieskie odcienie",
                "model": "nanobanana",
                "size": "1024x1024",
                "style": "photorealistic"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Wygenerowany obraz",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/AiImageGenerateResponse"
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "success": true,
                  "data": {
                    "url": "https://storage.example.com/images/generated-abc123.png",
                    "model": "nanobanana"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/InsufficientCredits"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "500": {
            "description": "Błąd generowania obrazu",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "success": false,
                  "message": "Image generation failed: Content policy violation"
                }
              }
            }
          }
        }
      }
    },
    "/ai/generate-image-async": {
      "post": {
        "tags": [
          "AI"
        ],
        "summary": "Generuj obraz (asynchronicznie)",
        "description": "Asynchroniczne generowanie obrazu. Zwraca `job_id` do sprawdzania statusu.\n\nUżyj `/ai/check-image-status/{jobId}` aby sprawdzić postęp.\n\nRate limit: 10 żądań/minutę per workspace\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "prompt"
                ],
                "properties": {
                  "prompt": {
                    "type": "string",
                    "maxLength": 5000
                  },
                  "model": {
                    "type": "string",
                    "nullable": true
                  },
                  "reference_image": {
                    "type": "string",
                    "description": "URL obrazu referencyjnego",
                    "nullable": true
                  },
                  "item_id": {
                    "type": "integer",
                    "description": "ID elementu Drive do powiązania",
                    "nullable": true
                  }
                }
              },
              "example": {
                "prompt": "Futurystyczna grafika produktowa dla smartwatcha",
                "model": "gemini-3-pro-image-preview",
                "reference_image": "https://example.com/reference.jpg"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Zadanie uruchomione",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/AiImageAsyncResponse"
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "success": true,
                  "data": {
                    "job_id": "550e8400-e29b-41d4-a716-446655440000",
                    "status": "pending",
                    "model": "gemini-3-pro-image-preview"
                  },
                  "message": "Image generation started"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/InsufficientCredits"
          }
        }
      }
    },
    "/ai/check-image-status/{jobId}": {
      "get": {
        "tags": [
          "AI"
        ],
        "summary": "Status generowania obrazu",
        "description": "Sprawdza status asynchronicznego zadania generowania obrazu",
        "parameters": [
          {
            "name": "jobId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "example": "550e8400-e29b-41d4-a716-446655440000"
          }
        ],
        "responses": {
          "200": {
            "description": "Status zadania",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/AiJobStatus"
                        }
                      }
                    }
                  ]
                },
                "examples": {
                  "pending": {
                    "summary": "Zadanie w kolejce",
                    "value": {
                      "success": true,
                      "data": {
                        "job_id": "550e8400-e29b-41d4-a716-446655440000",
                        "status": "pending",
                        "progress": 0,
                        "stage": "W kolejce...",
                        "image_url": null,
                        "error": null
                      }
                    }
                  },
                  "processing": {
                    "summary": "Zadanie w trakcie",
                    "value": {
                      "success": true,
                      "data": {
                        "job_id": "550e8400-e29b-41d4-a716-446655440000",
                        "status": "processing",
                        "progress": 45,
                        "stage": "Generowanie obrazu...",
                        "image_url": null,
                        "error": null
                      }
                    }
                  },
                  "completed": {
                    "summary": "Zadanie zakończone",
                    "value": {
                      "success": true,
                      "data": {
                        "job_id": "550e8400-e29b-41d4-a716-446655440000",
                        "status": "completed",
                        "progress": 100,
                        "stage": "Zakończone",
                        "image_url": "https://storage.example.com/images/generated-123.png",
                        "error": null
                      }
                    }
                  },
                  "failed": {
                    "summary": "Zadanie zakończone błędem",
                    "value": {
                      "success": true,
                      "data": {
                        "job_id": "550e8400-e29b-41d4-a716-446655440000",
                        "status": "failed",
                        "progress": 0,
                        "stage": null,
                        "image_url": null,
                        "error": "Content policy violation"
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Zadanie nie znalezione lub wygasło",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "success": false,
                  "message": "Job not found or expired"
                }
              }
            }
          }
        }
      }
    },
    "/ai/chat": {
      "post": {
        "tags": [
          "AI"
        ],
        "summary": "Chat z AI",
        "description": "Konwersacja z modelem AI. Pozwala na wieloturowy dialog.\n\nRate limit: 20 żądań/minutę per workspace\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AiChatRequest"
              },
              "example": {
                "messages": [
                  {
                    "role": "system",
                    "content": "Jesteś kreatywnym copywriterem specjalizującym się w reklamach"
                  },
                  {
                    "role": "user",
                    "content": "Zaproponuj 3 hasła reklamowe dla kawiarni"
                  }
                ],
                "model": "gemini-3-pro-preview",
                "max_tokens": 500,
                "temperature": 0.9
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Odpowiedź AI",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/AiChatResponse"
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "success": true,
                  "data": {
                    "message": {
                      "role": "assistant",
                      "content": "Oto 3 propozycje haseł reklamowych dla kawiarni:\n\n1. \"Twoja przerwa na kawę, nasza pasja w każdej filiżance\"\n2. \"Gdzie aromat spotyka się z chwilą relaksu\"\n3. \"Kawa jak rytuał - znajdź swój smak dnia\"\n"
                    },
                    "usage": {
                      "prompt_tokens": 35,
                      "completion_tokens": 62,
                      "total_tokens": 97
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/InsufficientCredits"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/ai/check-status/{jobId}": {
      "get": {
        "tags": [
          "AI"
        ],
        "summary": "Status ogólnego zadania AI",
        "description": "Sprawdza status asynchronicznego zadania AI (tekst, pole formularza)",
        "parameters": [
          {
            "name": "jobId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "example": "550e8400-e29b-41d4-a716-446655440000"
          }
        ],
        "responses": {
          "200": {
            "description": "Status zadania",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": {
                    "job_id": "550e8400-e29b-41d4-a716-446655440000",
                    "status": "completed",
                    "result": {
                      "text": "Wygenerowana treść..."
                    },
                    "error": null,
                    "started_at": "2024-03-15T10:00:00Z",
                    "completed_at": "2024-03-15T10:00:05Z"
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/agent/conversations": {
      "get": {
        "tags": [
          "Agent"
        ],
        "summary": "Lista konwersacji agenta",
        "description": "Zwraca listę konwersacji dla bieżącego projektu, posortowanych od najnowszej.\n\nKonwersacje są powiązane z projektem przez header `X-Project`.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "$ref": "#/components/parameters/ProjectHeader"
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Limit wyników (domyślnie 20, max 100)",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista konwersacji",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/AgentConversation"
                          }
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "success": true,
                  "data": [
                    {
                      "id": 42,
                      "title": "Analiza strony internetowej",
                      "status": "active",
                      "agent_definition_id": 1,
                      "messages_count": 8,
                      "created_at": "2024-03-10T14:00:00Z",
                      "updated_at": "2024-03-10T14:30:00Z"
                    },
                    {
                      "id": 41,
                      "title": "Generowanie treści SEO",
                      "status": "active",
                      "agent_definition_id": null,
                      "messages_count": 3,
                      "created_at": "2024-03-09T10:00:00Z",
                      "updated_at": "2024-03-09T10:15:00Z"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "tags": [
          "Agent"
        ],
        "summary": "Utwórz nową konwersację",
        "description": "Tworzy nową konwersację z opcjonalnym przypisaniem do agenta\n(np. `site_auditor`, `general_assistant`) i niestandardowym tytułem.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "agent_definition_id": {
                    "type": "integer",
                    "nullable": true,
                    "description": "ID definicji agenta",
                    "example": 1
                  },
                  "title": {
                    "type": "string",
                    "nullable": true,
                    "maxLength": 255,
                    "description": "Tytuł konwersacji",
                    "example": "Nowa analiza SEO"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Konwersacja utworzona",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "integer",
                              "example": 43
                            },
                            "title": {
                              "type": "string",
                              "example": "Nowa analiza SEO"
                            },
                            "messages": {
                              "type": "array",
                              "items": {
                                "$ref": "#/components/schemas/AgentMessage"
                              }
                            },
                            "status": {
                              "type": "string",
                              "example": "active"
                            }
                          }
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "success": true,
                  "data": {
                    "id": 43,
                    "title": "Nowa analiza SEO",
                    "messages": [],
                    "status": "active"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/agent/conversations/{id}": {
      "get": {
        "tags": [
          "Agent"
        ],
        "summary": "Szczegóły konwersacji",
        "description": "Zwraca pełne dane konwersacji wraz z wiadomościami, assetami\ni metadanymi agenta. Użyteczne do wyświetlenia pełnej historii rozmowy.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "ID konwersacji",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Dane konwersacji z wiadomościami i assetami",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": {
                    "conversation": {
                      "id": 42,
                      "title": "Analiza strony internetowej",
                      "status": "active",
                      "agent_definition_id": 1
                    },
                    "messages": [
                      {
                        "role": "user",
                        "content": "Przeanalizuj stronę example.com"
                      },
                      {
                        "role": "assistant",
                        "content": "Analizuję stronę...",
                        "tool_calls": [
                          {
                            "name": "fetch_webpage",
                            "arguments": {
                              "url": "https://example.com"
                            }
                          }
                        ]
                      }
                    ],
                    "assets": []
                  }
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "put": {
        "tags": [
          "Agent"
        ],
        "summary": "Aktualizuj konwersację",
        "description": "Aktualizuje tytuł, status lub metadane konwersacji.\n\nDozwolone statusy: `active`, `archived`, `closed`.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "ID konwersacji",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "maxLength": 255,
                    "nullable": true,
                    "description": "Nowy tytuł konwersacji",
                    "example": "Zaktualizowany tytuł"
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "active",
                      "archived",
                      "closed"
                    ],
                    "nullable": true,
                    "example": "archived"
                  },
                  "metadata": {
                    "type": "object",
                    "nullable": true,
                    "description": "Dowolne metadane konwersacji"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Konwersacja zaktualizowana",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": {
                    "id": 42,
                    "title": "Zaktualizowany tytuł",
                    "status": "archived"
                  }
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "delete": {
        "tags": [
          "Agent"
        ],
        "summary": "Usuń konwersację",
        "description": "Usuwa konwersację wraz ze wszystkimi wiadomościami.\n\n**UWAGA:** Ta operacja jest nieodwracalna!\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "ID konwersacji",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Konwersacja usunięta"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/agent/conversations/{id}/truncate": {
      "post": {
        "tags": [
          "Agent"
        ],
        "summary": "Przytnij wiadomości konwersacji",
        "description": "Usuwa wiadomości od podanego indeksu w górę.\nUżywane do cofania historii konwersacji (np. po błędnej odpowiedzi agenta).\n\nIndeks jest 0-based — `from_index: 5` usunie wiadomości od 5. pozycji do końca.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "ID konwersacji",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "from_index"
                ],
                "properties": {
                  "from_index": {
                    "type": "integer",
                    "minimum": 0,
                    "description": "Indeks od którego usunąć wiadomości (0-based)",
                    "example": 5
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Wiadomości przycięte",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": {
                    "messages_count": 5
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/agent/conversations/{id}/inspector": {
      "get": {
        "tags": [
          "Agent"
        ],
        "summary": "Dane inspektora narzędzi",
        "description": "Zwraca tool_calls z wiadomości asystenta w konwersacji.\nUżywane do debugowania i podglądu wywołań narzędzi agenta.\n\nFiltruje wiadomości — zwraca tylko te z roli `assistant` zawierające `tool_calls`.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "ID konwersacji",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Dane inspektora",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": {
                    "conversation_id": 42,
                    "entries": [
                      {
                        "role": "assistant",
                        "content": "Pobieram stronę...",
                        "tool_calls": [
                          {
                            "name": "fetch_webpage",
                            "arguments": {
                              "url": "https://example.com"
                            }
                          }
                        ]
                      },
                      {
                        "role": "assistant",
                        "content": null,
                        "tool_calls": [
                          {
                            "name": "generate_content",
                            "arguments": {
                              "prompt": "Napisz podsumowanie"
                            }
                          }
                        ]
                      }
                    ]
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/agent/chat": {
      "post": {
        "tags": [
          "Agent"
        ],
        "summary": "Uproszczony chat z agentem",
        "description": "Uproszczony endpoint — automatycznie tworzy konwersację jeśli nie podano `conversation_id`.\n\nZwraca `job_id` do śledzenia statusu odpowiedzi (asynchronicznie przez WebSocket\nlub polling GET `/agent/job-status/{jobId}`).\n\nRate limit: 20 żądań/minutę per workspace\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "message"
                ],
                "properties": {
                  "message": {
                    "type": "string",
                    "maxLength": 50000,
                    "description": "Wiadomość do agenta",
                    "example": "Przeanalizuj stronę anthropic.com"
                  },
                  "agent": {
                    "type": "string",
                    "nullable": true,
                    "description": "Slug agenta (np. site_auditor, general_assistant, page_generator)",
                    "example": "site_auditor"
                  },
                  "conversation_id": {
                    "type": "integer",
                    "nullable": true,
                    "description": "ID istniejącej konwersacji (kontynuacja)",
                    "example": 42
                  },
                  "model": {
                    "type": "string",
                    "nullable": true,
                    "description": "Override modelu AI"
                  },
                  "image_model": {
                    "type": "string",
                    "nullable": true,
                    "description": "Override modelu do generowania obrazów"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Job uruchomiony",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "job_id": {
                              "type": "string",
                              "format": "uuid"
                            },
                            "conversation_id": {
                              "type": "integer"
                            },
                            "status": {
                              "type": "string",
                              "enum": [
                                "pending"
                              ]
                            },
                            "message": {
                              "type": "string"
                            }
                          }
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "success": true,
                  "data": {
                    "job_id": "550e8400-e29b-41d4-a716-446655440000",
                    "conversation_id": 43,
                    "status": "pending",
                    "message": "Job uruchomiony. Sprawdź status: GET /api/v1/jobs/agent/550e8400.../status"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "description": "Job już jest w trakcie przetwarzania",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "success": false,
                  "message": "Job już jest w trakcie przetwarzania."
                }
              }
            }
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "description": "Zbyt wiele zapytań (rate limit)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "success": false,
                  "message": "Zbyt wiele zapytań. Spróbuj za 30 sekund."
                }
              }
            }
          }
        }
      }
    },
    "/agent/conversations/{id}/message": {
      "post": {
        "tags": [
          "Agent"
        ],
        "summary": "Wyślij wiadomość do agenta",
        "description": "Wysyła wiadomość do istniejącej konwersacji.\nUruchamia asynchroniczny job przetwarzający wiadomość.\n\nZwraca `job_id` do śledzenia statusu odpowiedzi.\n\nRate limit: 20 żądań/minutę per workspace\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "ID konwersacji",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "message"
                ],
                "properties": {
                  "message": {
                    "type": "string",
                    "maxLength": 50000,
                    "description": "Treść wiadomości do agenta",
                    "example": "Podaj więcej szczegółów o SEO tej strony"
                  },
                  "agent_definition_id": {
                    "type": "integer",
                    "nullable": true,
                    "description": "Override ID definicji agenta"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Wiadomość wysłana, job uruchomiony",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": {
                    "job_id": "550e8400-e29b-41d4-a716-446655440000",
                    "status": "pending"
                  }
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "description": "Job już jest w trakcie przetwarzania",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "description": "Zbyt wiele zapytań (rate limit)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/agent/job-status/{jobId}": {
      "get": {
        "tags": [
          "Agent"
        ],
        "summary": "Sprawdź status zadania agenta",
        "description": "Sprawdza status asynchronicznego zadania agenta.\n\nStatusy: `pending`, `processing`, `completed`, `failed`.\n\nWynik dostępny w polu `result` po zakończeniu.\n",
        "parameters": [
          {
            "name": "jobId",
            "in": "path",
            "required": true,
            "description": "UUID zadania",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "example": "550e8400-e29b-41d4-a716-446655440000"
          }
        ],
        "responses": {
          "200": {
            "description": "Status zadania",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/AgentJobStatus"
                        }
                      }
                    }
                  ]
                },
                "examples": {
                  "completed": {
                    "summary": "Zadanie zakończone",
                    "value": {
                      "success": true,
                      "data": {
                        "job_id": "550e8400-e29b-41d4-a716-446655440000",
                        "status": "completed",
                        "progress": 100,
                        "result": {
                          "response": "Analiza strony zakończona..."
                        },
                        "error": null
                      }
                    }
                  },
                  "processing": {
                    "summary": "Zadanie w trakcie",
                    "value": {
                      "success": true,
                      "data": {
                        "job_id": "550e8400-e29b-41d4-a716-446655440000",
                        "status": "processing",
                        "progress": 45,
                        "result": null,
                        "error": null
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Zadanie nie istnieje lub wygasło",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "success": false,
                  "message": "Job nie istnieje lub wygasł"
                }
              }
            }
          }
        }
      }
    },
    "/templates": {
      "get": {
        "tags": [
          "Templates"
        ],
        "summary": "Lista szablonów",
        "description": "Zwraca listę szablonów w bieżącym projekcie/workspace.\n\nWspiera filtrowanie po typie i wyszukiwanie po nazwie.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "$ref": "#/components/parameters/ProjectHeader"
          },
          {
            "name": "type",
            "in": "query",
            "description": "Filtruj po typie szablonu",
            "schema": {
              "type": "string",
              "example": "ad"
            }
          },
          {
            "name": "search",
            "in": "query",
            "description": "Szukaj po nazwie szablonu",
            "schema": {
              "type": "string",
              "example": "banner"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista szablonów",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Template"
                          }
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "success": true,
                  "data": [
                    {
                      "id": 1,
                      "name": "Banner reklamowy",
                      "code": "banner_reklamowy",
                      "description": "Szablon dla banerów reklamowych",
                      "type": "ad",
                      "is_active": true,
                      "created_at": "2024-01-15T10:00:00Z"
                    },
                    {
                      "id": 2,
                      "name": "Post na social media",
                      "code": "social_media_post",
                      "type": "text",
                      "is_active": true,
                      "created_at": "2024-02-01T14:00:00Z"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "tags": [
          "Templates"
        ],
        "summary": "Utwórz szablon",
        "description": "Tworzy nowy szablon z definicją schematu pól.\n\nSzablon definiuje strukturę formularza (pola, typy, walidacja)\nużywaną do tworzenia elementów Drive.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "$ref": "#/components/parameters/ProjectHeader"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TemplateCreate"
              },
              "example": {
                "name": "Banner reklamowy",
                "code": "banner_reklamowy",
                "description": "Szablon dla banerów reklamowych",
                "type": "ad",
                "button_name": "Utwórz banner",
                "button_icon": "🖼️",
                "schema_definition": {
                  "fields": [
                    {
                      "type": "text",
                      "label": "Nagłówek",
                      "placeholder": "Wpisz nagłówek...",
                      "required": true,
                      "ai_enabled": true,
                      "ai_system_prompt": "Napisz chwytliwy nagłówek reklamowy"
                    },
                    {
                      "type": "textarea",
                      "label": "Opis",
                      "placeholder": "Treść reklamy...",
                      "limit": 500
                    },
                    {
                      "type": "image",
                      "label": "Tło",
                      "required": true
                    }
                  ],
                  "show_assets": true
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Szablon utworzony",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/Template"
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "success": true,
                  "data": {
                    "id": 5,
                    "name": "Banner reklamowy",
                    "code": "banner_reklamowy",
                    "type": "ad"
                  },
                  "message": "Szablon utworzony"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/templates/{id}": {
      "get": {
        "tags": [
          "Templates"
        ],
        "summary": "Szczegóły szablonu",
        "description": "Zwraca pełne dane szablonu wraz z definicją schematu i polami",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "ID szablonu",
            "schema": {
              "type": "integer"
            },
            "example": 1
          }
        ],
        "responses": {
          "200": {
            "description": "Dane szablonu",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/Template"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "put": {
        "tags": [
          "Templates"
        ],
        "summary": "Aktualizuj szablon",
        "description": "Aktualizuje dane szablonu. Wszystkie pola są opcjonalne.\n\nZmiana `schema_definition` nadpisuje całą definicję schematu.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "ID szablonu",
            "schema": {
              "type": "integer"
            },
            "example": 1
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 255
                  },
                  "code": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 100,
                    "pattern": "^[a-z0-9_]+$"
                  },
                  "description": {
                    "type": "string",
                    "nullable": true,
                    "maxLength": 2000
                  },
                  "type": {
                    "type": "string",
                    "nullable": true,
                    "maxLength": 100
                  },
                  "button_name": {
                    "type": "string",
                    "nullable": true,
                    "maxLength": 100
                  },
                  "button_icon": {
                    "type": "string",
                    "nullable": true,
                    "maxLength": 10
                  },
                  "schema_definition": {
                    "type": "object",
                    "nullable": true
                  },
                  "is_active": {
                    "type": "boolean"
                  },
                  "show_in_types": {
                    "type": "boolean"
                  }
                }
              },
              "example": {
                "name": "Banner reklamowy v2",
                "description": "Zaktualizowany szablon banerów"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Szablon zaktualizowany",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": {
                    "id": 5,
                    "name": "Banner reklamowy v2",
                    "code": "banner_reklamowy"
                  },
                  "message": "Szablon zaktualizowany"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      },
      "delete": {
        "tags": [
          "Templates"
        ],
        "summary": "Usuń szablon",
        "description": "Soft-delete szablonu. Można przywrócić przez POST `/templates/{id}/restore`.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "ID szablonu",
            "schema": {
              "type": "integer"
            },
            "example": 1
          }
        ],
        "responses": {
          "204": {
            "description": "Szablon usunięty"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/templates/{id}/restore": {
      "post": {
        "tags": [
          "Templates"
        ],
        "summary": "Przywróć usunięty szablon",
        "description": "Przywraca soft-deleted szablon",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "ID szablonu",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Szablon przywrócony",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": {
                    "id": 5,
                    "name": "Banner reklamowy"
                  },
                  "message": "Szablon przywrócony"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/templates/{id}/duplicate": {
      "post": {
        "tags": [
          "Templates"
        ],
        "summary": "Duplikuj szablon",
        "description": "Tworzy kopię szablonu z automatycznie wygenerowaną nazwą i kodem",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "ID szablonu do zduplikowania",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Szablon zduplikowany",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": {
                    "id": 6,
                    "name": "Banner reklamowy (kopia)",
                    "code": "banner_reklamowy_copy"
                  },
                  "message": "Szablon zduplikowany"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/website/pages/{id}": {
      "get": {
        "tags": [
          "Website Pages"
        ],
        "summary": "Szczegóły strony",
        "description": "Zwraca dane strony wraz z HTML i wyekstrahowanymi sekcjami.\n\nSekcje są rozpoznawane na podstawie atrybutów `data-section` i `data-id` w HTML.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "ID strony",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Dane strony z sekcjami",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/WebsitePage"
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "success": true,
                  "data": {
                    "id": 1,
                    "name": "Strona główna",
                    "slug": "strona-glowna",
                    "html": "<section data-section='hero'>...</section>",
                    "sections": [
                      {
                        "id": "hero",
                        "type": "hero",
                        "html": "<h1>Witaj</h1><p>Opis...</p>"
                      },
                      {
                        "id": "features",
                        "type": "features",
                        "html": "<div class='grid'>...</div>"
                      }
                    ],
                    "show_in_menu": true,
                    "order": 0
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "put": {
        "tags": [
          "Website Pages"
        ],
        "summary": "Aktualizuj stronę",
        "description": "Aktualizuje metadane strony: nazwę, slug, tagi meta (title, description),\nwidoczność w menu i kolejność.\n\nWszystkie pola są opcjonalne.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "ID strony",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 255,
                    "nullable": true,
                    "example": "Strona główna"
                  },
                  "title": {
                    "type": "string",
                    "maxLength": 255,
                    "nullable": true,
                    "description": "Meta tag title",
                    "example": "Strona główna - Moja Firma"
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 500,
                    "nullable": true,
                    "description": "Meta tag description",
                    "example": "Opis strony dla SEO"
                  },
                  "slug": {
                    "type": "string",
                    "maxLength": 100,
                    "nullable": true,
                    "example": "strona-glowna"
                  },
                  "show_in_menu": {
                    "type": "boolean",
                    "nullable": true
                  },
                  "order": {
                    "type": "integer",
                    "nullable": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Strona zaktualizowana",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": {
                    "id": 1,
                    "name": "Strona główna",
                    "slug": "strona-glowna"
                  },
                  "message": "Page updated"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      },
      "delete": {
        "tags": [
          "Website Pages"
        ],
        "summary": "Usuń stronę",
        "description": "Usuwa stronę z projektu website",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "ID strony",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Strona usunięta"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/website/{projectId}/pages": {
      "post": {
        "tags": [
          "Website Pages"
        ],
        "summary": "Utwórz nową stronę",
        "description": "Dodaje nową stronę do projektu website",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "projectId",
            "in": "path",
            "required": true,
            "description": "ID projektu website",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 255,
                    "example": "O nas"
                  },
                  "slug": {
                    "type": "string",
                    "maxLength": 100,
                    "nullable": true,
                    "example": "o-nas"
                  },
                  "html": {
                    "type": "string",
                    "nullable": true,
                    "description": "Początkowy HTML strony",
                    "example": "<section><h1>O nas</h1></section>"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Strona utworzona",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": {
                    "id": 5,
                    "name": "O nas",
                    "slug": "o-nas"
                  },
                  "message": "Page created"
                }
              }
            }
          },
          "404": {
            "description": "Projekt nie znaleziony",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "success": false,
                  "message": "Website project not found"
                }
              }
            }
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/pipelines": {
      "get": {
        "tags": [
          "Pipelines"
        ],
        "summary": "Lista pipeline'ów",
        "description": "Zwraca listę pipeline'ów w bieżącym projekcie.\n\nPipeline to wizualny workflow składający się z node'ów (węzłów)\npołączonych edge'ami (krawędziami).\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          }
        ],
        "responses": {
          "200": {
            "description": "Lista pipeline'ów",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Pipeline"
                          }
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "success": true,
                  "data": [
                    {
                      "id": 1,
                      "name": "Generowanie kampanii",
                      "description": "Pipeline do automatycznego generowania materiałów",
                      "nodes": [],
                      "edges": [],
                      "created_at": "2024-01-15T10:00:00Z"
                    },
                    {
                      "id": 2,
                      "name": "Analiza konkurencji",
                      "description": null,
                      "created_at": "2024-02-01T14:00:00Z"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "tags": [
          "Pipelines"
        ],
        "summary": "Utwórz pipeline",
        "description": "Tworzy nowy pipeline z opcjonalnymi node'ami i edge'ami.\n\nNazwa musi być unikalna w ramach projektu.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PipelineCreate"
              },
              "example": {
                "name": "Nowy pipeline",
                "description": "Workflow do generowania treści",
                "nodes": [
                  {
                    "id": "node_1",
                    "type": "prompt",
                    "position": {
                      "x": 100,
                      "y": 100
                    },
                    "data": {
                      "prompt": "Napisz tekst reklamowy dla {{product}}"
                    }
                  },
                  {
                    "id": "node_2",
                    "type": "ai_text",
                    "position": {
                      "x": 400,
                      "y": 100
                    },
                    "data": {
                      "model": "gemini-3-pro-preview"
                    }
                  }
                ],
                "edges": [
                  {
                    "id": "edge_1",
                    "source": "node_1",
                    "target": "node_2",
                    "sourceHandle": "prompt",
                    "targetHandle": "input"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Pipeline utworzony",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/Pipeline"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/pipelines/{pipeline}": {
      "get": {
        "tags": [
          "Pipelines"
        ],
        "summary": "Szczegóły pipeline",
        "description": "Zwraca pełne dane pipeline z node'ami, edge'ami i viewportem",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "pipeline",
            "in": "path",
            "required": true,
            "description": "ID pipeline",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Dane pipeline",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/Pipeline"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "put": {
        "tags": [
          "Pipelines"
        ],
        "summary": "Aktualizuj pipeline",
        "description": "Aktualizuje dane pipeline. Wszystkie pola są opcjonalne.\n\nJeśli podano `nodes`, `edges` lub `viewport`, nadpisują one istniejące dane.\nJeśli nie podano — pozostają bez zmian.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "pipeline",
            "in": "path",
            "required": true,
            "description": "ID pipeline",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 255
                  },
                  "description": {
                    "type": "string",
                    "nullable": true,
                    "maxLength": 2000
                  },
                  "nodes": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/PipelineNode"
                    }
                  },
                  "edges": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/PipelineEdge"
                    }
                  },
                  "viewport": {
                    "type": "object",
                    "properties": {
                      "x": {
                        "type": "number"
                      },
                      "y": {
                        "type": "number"
                      },
                      "zoom": {
                        "type": "number"
                      }
                    }
                  }
                }
              },
              "example": {
                "name": "Zaktualizowany pipeline",
                "description": "Nowy opis"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Pipeline zaktualizowany",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/Pipeline"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      },
      "delete": {
        "tags": [
          "Pipelines"
        ],
        "summary": "Usuń pipeline",
        "description": "Usuwa pipeline wraz ze wszystkimi node'ami i edge'ami.\n\n**UWAGA:** Ta operacja jest nieodwracalna!\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "pipeline",
            "in": "path",
            "required": true,
            "description": "ID pipeline",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Pipeline usunięty"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/pipelines/node-definitions": {
      "get": {
        "tags": [
          "Pipelines"
        ],
        "summary": "Definicje typów node'ów",
        "description": "Zwraca metadane wszystkich dostępnych typów node'ów: inputs/outputs,\nkategorie, kolory, ikony, flagi.\n\nUżywane przez frontend Flow Editor do konfiguracji palety node'ów.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          }
        ],
        "responses": {
          "200": {
            "description": "Definicje node'ów",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": [
                    {
                      "type": "prompt",
                      "label": "Prompt",
                      "category": "input",
                      "color": "#4CAF50",
                      "icon": "chat",
                      "inputs": [],
                      "outputs": [
                        {
                          "handle": "prompt",
                          "type": "string"
                        }
                      ]
                    },
                    {
                      "type": "ai_text",
                      "label": "AI Text",
                      "category": "ai",
                      "color": "#2196F3",
                      "inputs": [
                        {
                          "handle": "input",
                          "type": "string"
                        }
                      ],
                      "outputs": [
                        {
                          "handle": "text",
                          "type": "string"
                        }
                      ]
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/pipelines/as-tools": {
      "get": {
        "tags": [
          "Pipelines"
        ],
        "summary": "Lista pipeline'ów jako narzędzia",
        "description": "Zwraca pipeline'y w formacie narzędzi dla agenta AI z ich inputami.\n\nUżywane do dynamicznego udostępniania pipeline'ów jako narzędzi agentowi.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          }
        ],
        "responses": {
          "200": {
            "description": "Lista pipeline'ów jako narzędzia",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": [
                    {
                      "id": 1,
                      "name": "Generowanie kampanii",
                      "description": "Generuje materiały kampanii reklamowej",
                      "inputs": [
                        {
                          "name": "product",
                          "type": "string",
                          "required": true
                        },
                        {
                          "name": "target_audience",
                          "type": "string",
                          "required": false
                        }
                      ]
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/pipelines/execute": {
      "post": {
        "tags": [
          "Pipelines"
        ],
        "summary": "Uruchom pipeline",
        "description": "Uruchamia pipeline po ID lub nazwie.\n\nTryby:\n- **Asynchroniczny** (domyślny): zwraca `execution_id` do sprawdzania statusu\n- **Synchroniczny** (`sync: true`): czeka na wynik (max `timeout` sekund, domyślnie 60)\n\nRate limit: 20 żądań/minutę per workspace\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "integer",
                    "nullable": true,
                    "description": "ID pipeline (opcjonalne jeśli podano name)",
                    "example": 1
                  },
                  "name": {
                    "type": "string",
                    "nullable": true,
                    "description": "Nazwa pipeline (opcjonalne jeśli podano id)",
                    "example": "Generowanie kampanii"
                  },
                  "inputs": {
                    "type": "object",
                    "description": "Inputy dla workflow (klucz-wartość)",
                    "additionalProperties": true,
                    "example": {
                      "product": "Smartwatch XYZ",
                      "target_audience": "Młodzi profesjonaliści"
                    }
                  },
                  "sync": {
                    "type": "boolean",
                    "default": false,
                    "description": "Czekaj na wynik synchronicznie"
                  },
                  "timeout": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 120,
                    "default": 60,
                    "description": "Timeout w sekundach (tylko dla sync=true)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Workflow uruchomiony lub wykonany",
            "content": {
              "application/json": {
                "examples": {
                  "async": {
                    "summary": "Uruchomienie asynchroniczne",
                    "value": {
                      "success": true,
                      "data": {
                        "execution_id": "exec_550e8400",
                        "status": "pending",
                        "message": "Pipeline started"
                      }
                    }
                  },
                  "sync": {
                    "summary": "Wykonanie synchroniczne",
                    "value": {
                      "success": true,
                      "data": {
                        "execution_id": "exec_550e8400",
                        "status": "completed",
                        "results": {
                          "node_1": {
                            "_meta": {
                              "nodeType": "prompt",
                              "success": true
                            },
                            "data": {
                              "prompt": {
                                "value": "Tekst prompta..."
                              }
                            }
                          },
                          "node_2": {
                            "_meta": {
                              "nodeType": "ai_text",
                              "success": true
                            },
                            "data": {
                              "text": {
                                "value": "Wygenerowany tekst reklamowy..."
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "Pipeline nie znaleziony",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "Pipeline już jest w trakcie wykonywania"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "description": "Zbyt wiele zapytań (rate limit)"
          }
        }
      }
    },
    "/pipelines/workflow-status/{executionId}": {
      "get": {
        "tags": [
          "Pipelines"
        ],
        "summary": "Status wykonania workflow",
        "description": "Sprawdza status asynchronicznego wykonania pipeline",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "executionId",
            "in": "path",
            "required": true,
            "description": "ID wykonania workflow",
            "schema": {
              "type": "string"
            },
            "example": "exec_550e8400"
          }
        ],
        "responses": {
          "200": {
            "description": "Status wykonania",
            "content": {
              "application/json": {
                "examples": {
                  "running": {
                    "summary": "W trakcie",
                    "value": {
                      "success": true,
                      "data": {
                        "execution_id": "exec_550e8400",
                        "status": "processing",
                        "completed_nodes": 2,
                        "total_nodes": 5,
                        "current_node": "node_3"
                      }
                    }
                  },
                  "completed": {
                    "summary": "Zakończone",
                    "value": {
                      "success": true,
                      "data": {
                        "execution_id": "exec_550e8400",
                        "status": "completed",
                        "completed_nodes": 5,
                        "total_nodes": 5,
                        "results": {
                          "node_5": {
                            "_meta": {
                              "nodeType": "output",
                              "success": true
                            },
                            "data": {
                              "result": {
                                "value": "Finalny wynik pipeline..."
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/drive/{id}/with-assets": {
      "get": {
        "tags": [
          "Drive Assets"
        ],
        "summary": "Element z assetami",
        "description": "Zwraca element Drive wraz z powiązanymi assetami (obrazy, pliki kontekstowe)",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "ID elementu Drive",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Element z assetami",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": {
                    "item": {
                      "id": 123,
                      "name": "Kampania Q1",
                      "type": "ad"
                    },
                    "assets": [
                      {
                        "id": 10,
                        "name": "Logo.png",
                        "type": "image",
                        "file_url": "https://storage.example.com/logo.png"
                      },
                      {
                        "id": 11,
                        "name": "Brief.txt",
                        "type": "text"
                      }
                    ]
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/drive/{id}/assets": {
      "get": {
        "tags": [
          "Drive Assets"
        ],
        "summary": "Lista assetów elementu",
        "description": "Zwraca listę assetów powiązanych z elementem Drive",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "ID elementu Drive",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista assetów",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": [
                    {
                      "id": 10,
                      "name": "Logo.png",
                      "type": "image"
                    },
                    {
                      "id": 11,
                      "name": "Brief.txt",
                      "type": "text"
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/drive/{id}/assets/sync": {
      "post": {
        "tags": [
          "Drive Assets"
        ],
        "summary": "Synchronizuj assety",
        "description": "Synchronizuje assety elementu — ustawia dokładnie te assety,\nktóre podano w tablicy `asset_ids`. Usunie niepodane i doda nowe.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "ID elementu Drive",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "asset_ids": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    },
                    "example": [
                      10,
                      11,
                      15
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Assety zsynchronizowane",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": {
                    "synced_count": 3
                  },
                  "message": "Assety zsynchronizowane"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/drive/{itemId}/assets/{assetId}": {
      "delete": {
        "tags": [
          "Drive Assets"
        ],
        "summary": "Odłącz asset od elementu",
        "description": "Usuwa powiązanie assetu z elementem (nie kasuje samego assetu)",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          },
          {
            "name": "itemId",
            "in": "path",
            "required": true,
            "description": "ID elementu Drive",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "assetId",
            "in": "path",
            "required": true,
            "description": "ID assetu do odłączenia",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Asset odłączony",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "message": "Asset odłączony"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/drive/assets-for-picker": {
      "get": {
        "tags": [
          "Drive Assets"
        ],
        "summary": "Assety dla pickera",
        "description": "Zwraca listę assetów do wyświetlenia w asset picker modal.\nFiltruje elementy odpowiednie do użycia jako assety kontekstowe.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          }
        ],
        "responses": {
          "200": {
            "description": "Lista assetów",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": [
                    {
                      "id": 10,
                      "name": "Logo.png",
                      "type": "image",
                      "thumbnail_url": "https://storage.example.com/thumb/logo.png"
                    },
                    {
                      "id": 11,
                      "name": "Brand guidelines",
                      "type": "text"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/drive/items-by-ids": {
      "post": {
        "tags": [
          "Drive Assets"
        ],
        "summary": "Pobierz elementy po ID",
        "description": "Zwraca elementy Drive o podanych ID. Przydatne do batch-owego pobierania danych.",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "ids"
                ],
                "properties": {
                  "ids": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    },
                    "example": [
                      10,
                      11,
                      15,
                      23
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lista elementów",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": [
                    {
                      "id": 10,
                      "name": "Logo.png",
                      "type": "image"
                    },
                    {
                      "id": 11,
                      "name": "Brief.txt",
                      "type": "text"
                    },
                    {
                      "id": 15,
                      "name": "Folder kampanii",
                      "type": "folder"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/drive/stats": {
      "get": {
        "tags": [
          "Drive"
        ],
        "summary": "Statystyki elementów Drive",
        "description": "Zwraca liczbę elementów pogrupowanych po typie dla bieżącego projektu",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceHeader"
          }
        ],
        "responses": {
          "200": {
            "description": "Statystyki",
            "content": {
              "application/json": {
                "example": {
                  "success": true,
                  "data": {
                    "image": 45,
                    "text": 23,
                    "landing_page": 5,
                    "folder": 12,
                    "prompt": 8
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    }
  }
}