openapi: 3.1.0
info:
  title: Foxli Public API
  version: 1.0.0
  description: |
    Official Foxli REST API (v1) for social media publishing, scheduling, analytics, workspace management, and webhooks.
    
    ### Authentication
    Authentication uses account-level Bearer API keys (`Authorization: Bearer fx_live_...` or `Authorization: Bearer fx_test_...`).
    API keys work across all workspaces the user owns or is an administrator of.
    
    ### Workspace Resolution
    On workspace-specific endpoints (channels, posts, media, analytics, webhooks), specify the workspace using:
    - `Foxli-Workspace: <workspace_id>` header, or
    - `workspace_id=<workspace_id>` query parameter or request body field.
    If omitted and your account owns or administers exactly one workspace, Foxli defaults to that workspace.
    
    ### Rate Limits
    Rate limits apply per account across all its API keys:
    - 120 requests / minute
    - 10,000 requests / day
    Rate limit state is communicated via `X-RateLimit-Limit`, `X-RateLimit-Remaining`, and `X-RateLimit-Reset` headers.
    
    ### Idempotency
    On `POST` requests, provide an `Idempotency-Key` header with a unique string (e.g. UUIDv4).
    Responses are cached for 24 hours to safely retry requests without duplicates.

    ### Webhooks
    Foxli can deliver real-time HTTP POST notifications to your endpoints for publishing and channel events.
    - **Endpoint Limits**: Up to 5 webhook endpoints per workspace.
    - **Signing Secret**: Generated upon creation (`whsec_` + 32 base62 characters). Shown only once via API (or revealed by workspace owner/admin in web app).
    - **Signature Verification**: Every request includes:
      - `Foxli-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256(secret, "<t>.<raw JSON body>")>`
      - `Foxli-Event: <type>`
      - `Foxli-Delivery: <delivery id>`
      - `User-Agent: Foxli-Webhooks/1.0`
      - `Content-Type: application/json`
    - **Payload Format**: `{ id: "evt_...", type: "...", created_at: "...", workspace_id: "...", data: { ... } }`
    - **Supported Events**: `post.published`, `post.failed`, `post.partially_published`, `channel.disconnected`.
    - **Retry Policy**: 5-minute scheduled retry cycle with 5 retries over 6+ hours (+1m, +5m, +30m, +2h, +6h) before being marked `dead`.
servers:
  - url: https://api.foxli.app/v1
    description: Production API
  - url: https://web.foxli.app/api/v1
    description: Production Web Gateway Fallback
security:
  - bearerAuth: []

paths:
  /me:
    get:
      summary: Get account details
      description: Returns the authenticated account profile, subscription plan tier, API key metadata, usable workspaces, and rate limit status.
      operationId: getMe
      responses:
        '200':
          description: Authenticated account details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MeResponse'
              example:
                user:
                  id: "usr_98a7bc6d"
                  email: "alex@example.com"
                  display_name: "Alex Creator"
                plan:
                  tier: "creator"
                  status: "active"
                  trial_phase: "active_paid"
                key:
                  id: "key_81a7b"
                  name: "Zapier Automation"
                  prefix: "fx_live_"
                  last4: "9A2F"
                  scopes:
                    - "posts:read"
                    - "posts:write"
                    - "channels:read"
                  created_at: "2026-11-01T10:00:00Z"
                rate_limit:
                  limit_per_minute: 120
                  limit_per_day: 10000
                  remaining_minute: 118
                  remaining_day: 9850
                workspaces:
                  - id: "ws_brand_primary"
                    name: "Main Brand"
                    role: "owner"
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/RateLimited'

  /workspaces:
    get:
      summary: List workspaces
      description: Lists all workspaces that the user owns or is an administrator of.
      operationId: listWorkspaces
      responses:
        '200':
          description: List of accessible workspaces
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Workspace'
                  next_cursor:
                    type: string
                    nullable: true
              example:
                data:
                  - id: "ws_brand_primary"
                    name: "Acme Social"
                    role: "owner"
                    timezone: "Asia/Kolkata"
                    channel_count: 4
                    created_at: "2026-01-15T08:30:00Z"
                next_cursor: null
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
    post:
      summary: Create workspace
      description: Creates a new workspace under the authenticated account (subject to plan quotas).
      operationId: createWorkspace
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
              properties:
                name:
                  type: string
                  example: "Agency Client Beta"
                timezone:
                  type: string
                  example: "Asia/Kolkata"
      responses:
        '201':
          description: Workspace created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Workspace'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'

  /workspaces/{id}:
    patch:
      summary: Update workspace
      description: Rename or update settings (timezone, posting schedule) for a workspace.
      operationId: updateWorkspace
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
          example: "ws_brand_primary"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  example: "Acme Media Global"
                timezone:
                  type: string
                  example: "America/New_York"
      responses:
        '200':
          description: Updated workspace
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Workspace'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'

  /workspaces/{id}/members:
    get:
      summary: List workspace members
      description: Returns members and their roles in the workspace (read-only in v1).
      operationId: listWorkspaceMembers
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
          example: "ws_brand_primary"
      responses:
        '200':
          description: Members list
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                  - next_cursor
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/WorkspaceMember'
                  next_cursor:
                    type: string
                    nullable: true
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'

  /channels:
    get:
      summary: List connected channels
      description: Lists all social channels connected to the active workspace.
      operationId: listChannels
      parameters:
        - $ref: '#/components/parameters/WorkspaceHeader'
        - $ref: '#/components/parameters/WorkspaceQuery'
      responses:
        '200':
          description: List of connected channels
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                  - next_cursor
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Channel'
                  next_cursor:
                    type: string
                    nullable: true
              example:
                next_cursor: null
                data:
                  - id: "ch_x_12345"
                    provider: "x"
                    handle: "acme_global"
                    display_name: "Acme Global"
                    status: "active"
                    avatar_url: "https://foxli.app/avatars/x_acme.jpg"
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'

  /posts:
    get:
      summary: List posts
      description: Returns paginated list of posts in the workspace, with optional status and channel filtering.
      operationId: listPosts
      parameters:
        - $ref: '#/components/parameters/WorkspaceHeader'
        - $ref: '#/components/parameters/WorkspaceQuery'
        - name: status
          in: query
          required: false
          schema:
            type: string
          example: "published"
        - name: channel_id
          in: query
          required: false
          schema:
            type: string
        - name: from
          in: query
          required: false
          schema:
            type: string
            format: date-time
        - name: to
          in: query
          required: false
          schema:
            type: string
            format: date-time
        - name: tag
          in: query
          required: false
          schema:
            type: string
        - $ref: '#/components/parameters/LimitParam'
        - $ref: '#/components/parameters/CursorParam'
      responses:
        '200':
          description: List of posts
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                  - next_cursor
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Post'
                  next_cursor:
                    type: string
                    nullable: true
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
    post:
      summary: Create post
      description: Creates a social media post across one or more connected channels. Supports drafting, queuing, custom scheduling, or publishing immediately.
      operationId: createPost
      parameters:
        - $ref: '#/components/parameters/WorkspaceHeader'
        - $ref: '#/components/parameters/WorkspaceQuery'
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreatePostRequest'
            example:
              mode: "schedule"
              channel_ids:
                - "ch_x_12345"
                - "ch_li_67890"
              content: "Excited to unveil our automated workflow today! 🚀 #productivity"
              scheduled_at: "2026-11-10T14:30:00Z"
              media_urls:
                - "https://storage.googleapis.com/foxli-media/launch_banner.png"
              first_comment: "Read our full documentation at https://foxli.app"
              tags: ["launch", "announcement"]
      responses:
        '201':
          description: Post successfully created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Post'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'

  /posts/{id}:
    get:
      summary: Get post details
      description: Returns full details and per-channel delivery results for a single post.
      operationId: getPost
      parameters:
        - $ref: '#/components/parameters/WorkspaceHeader'
        - $ref: '#/components/parameters/WorkspaceQuery'
        - name: id
          in: path
          required: true
          schema:
            type: string
          example: "pst_89fa12b"
      responses:
        '200':
          description: Post details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Post'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
    patch:
      summary: Update post
      description: Edit a draft, queued, or scheduled post.
      operationId: updatePost
      parameters:
        - $ref: '#/components/parameters/WorkspaceHeader'
        - $ref: '#/components/parameters/WorkspaceQuery'
        - name: id
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                content:
                  type: string
                scheduled_at:
                  type: string
                  format: date-time
                media_urls:
                  type: array
                  items:
                    type: string
                media_ids:
                  type: array
                  items:
                    type: string
                channel_ids:
                  type: array
                  items:
                    type: string
                first_comment:
                  type: string
                tags:
                  type: array
                  items:
                    type: string
                channel_overrides:
                  type: object
                  additionalProperties:
                    type: object
      responses:
        '200':
          description: Updated post
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Post'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          $ref: '#/components/responses/NotFound'
    delete:
      summary: Delete post
      description: Deletes a post and its associated metrics records.
      operationId: deletePost
      parameters:
        - $ref: '#/components/parameters/WorkspaceHeader'
        - $ref: '#/components/parameters/WorkspaceQuery'
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        '204':
          description: Post deleted successfully

  /media:
    post:
      summary: Import media from URL
      description: Imports an image or video from an external public URL into Foxli CDN storage (images ≤ 10 MB, videos ≤ 100 MB).
      operationId: importMedia
      parameters:
        - $ref: '#/components/parameters/WorkspaceHeader'
        - $ref: '#/components/parameters/WorkspaceQuery'
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - url
              properties:
                url:
                  type: string
                  format: uri
                  example: "https://images.unsplash.com/photo-1618005182384-a83a8bd57fbe"
                kind:
                  type: string
                  enum: [image, video]
                  example: "image"
      responses:
        '201':
          description: Media imported
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MediaImport'
        '400':
          $ref: '#/components/responses/BadRequest'

  /analytics/overview:
    get:
      summary: Get analytics overview
      description: Returns aggregate KPIs and daily engagement series for a date range and channels.
      operationId: getAnalyticsOverview
      parameters:
        - $ref: '#/components/parameters/WorkspaceHeader'
        - $ref: '#/components/parameters/WorkspaceQuery'
        - name: from
          in: query
          required: false
          schema:
            type: string
            format: date
          example: "2026-10-01"
        - name: to
          in: query
          required: false
          schema:
            type: string
            format: date
          example: "2026-10-31"
        - name: start_date
          in: query
          required: false
          schema:
            type: string
            format: date
          example: "2026-10-01"
        - name: end_date
          in: query
          required: false
          schema:
            type: string
            format: date
          example: "2026-10-31"
        - name: channel_ids
          in: query
          required: false
          schema:
            type: array
            items:
              type: string
      responses:
        '200':
          description: Analytics summary
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnalyticsOverview'

  /webhooks:
    get:
      summary: List webhook endpoints
      description: Returns all configured webhook subscriptions for the workspace (up to 5 per workspace).
      operationId: listWebhooks
      parameters:
        - $ref: '#/components/parameters/WorkspaceHeader'
        - $ref: '#/components/parameters/WorkspaceQuery'
      responses:
        '200':
          description: List of webhooks
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                  - next_cursor
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/WebhookEndpoint'
                  next_cursor:
                    type: string
                    nullable: true
    post:
      summary: Create webhook endpoint
      description: Subscribes a URL to workspace publishing and channel lifecycle events.
      operationId: createWebhook
      parameters:
        - $ref: '#/components/parameters/WorkspaceHeader'
        - $ref: '#/components/parameters/WorkspaceQuery'
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - url
                - events
              properties:
                url:
                  type: string
                  format: uri
                  example: "https://agency.example.com/api/foxli-events"
                events:
                  type: array
                  items:
                    type: string
                    enum: [post.published, post.failed, post.partially_published, channel.disconnected]
                  example: ["post.published", "post.failed"]
      responses:
        '201':
          description: Webhook endpoint registered
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WebhookEndpoint'

  /webhooks/{id}:
    delete:
      summary: Delete webhook endpoint
      description: Permanently removes a webhook subscription, its secret, and pending deliveries.
      operationId: deleteWebhook
      parameters:
        - $ref: '#/components/parameters/WorkspaceHeader'
        - $ref: '#/components/parameters/WorkspaceQuery'
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        '204':
          description: Webhook deleted successfully

  /webhooks/{id}/test:
    post:
      summary: Send test webhook event
      description: Enqueues an immediate ping test event to verify endpoint connectivity and HMAC-SHA256 signature verification.
      operationId: testWebhook
      parameters:
        - $ref: '#/components/parameters/WorkspaceHeader'
        - $ref: '#/components/parameters/WorkspaceQuery'
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        '202':
          description: Test ping enqueued
          content:
            application/json:
              schema:
                type: object
                properties:
                  enqueued:
                    type: boolean
                    example: true
                  delivery_id:
                    type: string
                    example: "del_test_wh_78a1bc"

components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: "fx_live_... / fx_test_..."
      description: Account-level API key from Foxli Settings.

  parameters:
    WorkspaceHeader:
      name: Foxli-Workspace
      in: header
      description: Target workspace ID. Required if account owns or admins more than one workspace.
      required: false
      schema:
        type: string
        example: "ws_brand_primary"
    WorkspaceQuery:
      name: workspace_id
      in: query
      description: Alternative way to pass workspace ID.
      required: false
      schema:
        type: string
        example: "ws_brand_primary"
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      description: Unique token for request idempotency (valid for 24 hours).
      required: false
      schema:
        type: string
        format: uuid
        example: "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d"
    LimitParam:
      name: limit
      in: query
      description: Max number of items to return (max 50, default 20).
      required: false
      schema:
        type: integer
        minimum: 1
        maximum: 50
        default: 20
    CursorParam:
      name: cursor
      in: query
      description: Pagination cursor string from previous response.
      required: false
      schema:
        type: string

  headers:
    X-RateLimit-Limit:
      schema:
        type: integer
      description: Request limit for current minute window.
    X-RateLimit-Remaining:
      schema:
        type: integer
      description: Requests remaining in current minute window.
    X-RateLimit-Reset:
      schema:
        type: integer
      description: Unix epoch time (in seconds) when rate limit resets.
    Retry-After:
      schema:
        type: integer
      description: Seconds before retrying request after HTTP 429.
    X-Request-Id:
      schema:
        type: string
      description: Unique tracking ID for the request.

  responses:
    BadRequest:
      description: Invalid request parameters or missing workspace context.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: "workspace_required"
              message: "workspace_id parameter or Foxli-Workspace header is required."
              request_id: "req_3a9e21"
    Unauthorized:
      description: Missing, invalid, or revoked API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: "invalid_api_key"
              message: "Invalid or revoked API key."
              request_id: "req_3a9e22"
    Forbidden:
      description: Insufficient scope, insufficient plan tier, or unauthorized workspace.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: "insufficient_scope"
              message: "API key lacks required scope: posts:write"
              request_id: "req_3a9e23"
    NotFound:
      description: Resource was not found.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: "not_found"
              message: "The requested resource does not exist."
              request_id: "req_3a9e24"
    RateLimited:
      description: Rate limit exceeded (120/min or 10,000/day).
      headers:
        Retry-After:
          $ref: '#/components/headers/Retry-After'
        X-RateLimit-Limit:
          $ref: '#/components/headers/X-RateLimit-Limit'
        X-RateLimit-Remaining:
          $ref: '#/components/headers/X-RateLimit-Remaining'
        X-RateLimit-Reset:
          $ref: '#/components/headers/X-RateLimit-Reset'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: "rate_limited"
              message: "Too many requests. Please slow down."
              request_id: "req_3a9e25"

  schemas:
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
            - request_id
          properties:
            code:
              type: string
              example: "invalid_api_key"
            message:
              type: string
              example: "Invalid or revoked API key."
            request_id:
              type: string
              example: "req_9fa872b"

    PaginationMeta:
      type: object
      properties:
        next_cursor:
          type: string
          nullable: true
          example: "cur_eyJpZCI6InBzdF8xMjMifQ"
        has_more:
          type: boolean
          example: false

    MeResponse:
      type: object
      required:
        - user
        - plan
        - key
        - rate_limit
        - workspaces
      properties:
        user:
          type: object
          properties:
            id:
              type: string
            email:
              type: string
            display_name:
              type: string
              nullable: true
        plan:
          type: object
          properties:
            tier:
              type: string
              enum: [free, creator, team]
            status:
              type: string
            trial_phase:
              type: string
              nullable: true
        key:
          type: object
          properties:
            id:
              type: string
            name:
              type: string
            prefix:
              type: string
            last4:
              type: string
            scopes:
              type: array
              items:
                type: string
            created_at:
              type: string
              format: date-time
        rate_limit:
          type: object
          properties:
            limit_per_minute:
              type: integer
            limit_per_day:
              type: integer
            remaining_minute:
              type: integer
            remaining_day:
              type: integer
        workspaces:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
              name:
                type: string
              role:
                type: string

    Workspace:
      type: object
      required:
        - id
        - name
        - role
      properties:
        id:
          type: string
          example: "ws_brand_primary"
        name:
          type: string
          example: "Acme Social"
        role:
          type: string
          enum: [owner, admin]
          example: "owner"
        timezone:
          type: string
          nullable: true
          example: "Asia/Kolkata"
        channel_count:
          type: integer
          example: 3
        created_at:
          type: string
          format: date-time

    WorkspaceMember:
      type: object
      required:
        - user_id
        - role
        - status
      properties:
        user_id:
          type: string
          example: "usr_98a7bc6d"
        name:
          type: string
          nullable: true
          example: "Alex Creator"
        email:
          type: string
          example: "teammate@example.com"
        role:
          type: string
          enum: [owner, admin, editor, viewer, client_admin, client_approver]
        status:
          type: string
          enum: [active, invited, removed]

    Channel:
      type: object
      required:
        - id
        - provider
        - handle
        - status
      properties:
        id:
          type: string
          example: "ch_x_12345"
        provider:
          type: string
          enum: [x, instagram, facebook, linkedin, threads, pinterest, youtube, bluesky]
        platform:
          type: string
          enum: [x, instagram, facebook, linkedin, threads, pinterest, youtube, bluesky]
        handle:
          type: string
          example: "acme_global"
        name:
          type: string
          example: "Acme Global"
        display_name:
          type: string
          example: "Acme Global"
        avatar_url:
          type: string
          nullable: true
        status:
          type: string
          enum: [active, paused, disconnected, connected, expired]
        account_type:
          type: string
          enum: [profile, page, channel, board]
          example: "profile"

    CreatePostRequest:
      type: object
      required:
        - mode
        - channel_ids
        - content
      properties:
        mode:
          type: string
          enum: [draft, queue, schedule, now]
          description: >-
            draft = save only; queue = next free slot in the workspace posting schedule (400 no_queue_slot if none);
            schedule = publish at scheduled_at (2 min to 1 year ahead); now = publish within about 2 minutes.
            For queue/schedule/now the response status is "scheduled"/"queued"; the final result arrives via
            GET /v1/posts/{id} or the post.published / post.failed webhooks.
          example: "schedule"
        channel_ids:
          type: array
          items:
            type: string
          example: ["ch_x_12345", "ch_li_67890"]
        content:
          type: string
          example: "Check out our latest release! #foxli"
        scheduled_at:
          type: string
          format: date-time
          example: "2026-11-10T15:00:00Z"
        media_urls:
          type: array
          items:
            type: string
        media_ids:
          type: array
          items:
            type: string
          description: Media IDs from POST /v1/media
        first_comment:
          type: string
        tags:
          type: array
          items:
            type: string
        channel_overrides:
          type: object
          additionalProperties:
            type: object
            properties:
              content:
                type: string
              media_urls:
                type: array
                items:
                  type: string

    Post:
      type: object
      required:
        - id
        - workspace_id
        - status
        - channel_ids
        - content
        - created_at
      properties:
        id:
          type: string
          example: "pst_89fa12b"
        workspace_id:
          type: string
          example: "ws_brand_primary"
        status:
          type: string
          enum: [draft, queued, scheduled, publishing, published, failed, partially_published]
        channel_ids:
          type: array
          items:
            type: string
        content:
          type: string
        media_urls:
          type: array
          items:
            type: string
        media_ids:
          type: array
          items:
            type: string
          description: Media IDs from POST /v1/media
        scheduled_at:
          type: string
          format: date-time
          nullable: true
        published_at:
          type: string
          format: date-time
          nullable: true
        created_at:
          type: string
          format: date-time
        results:
          type: array
          items:
            type: object
            properties:
              channel_id:
                type: string
              status:
                type: string
                enum: [success, failed]
              post_url:
                type: string
                nullable: true
              error_message:
                type: string
                nullable: true

    MediaImport:
      type: object
      required:
        - media_id
        - url
        - content_type
        - size_bytes
      properties:
        media_id:
          type: string
          example: "med_44a9bc8"
        kind:
          type: string
          enum: [image, video]
          example: "image"
        url:
          type: string
          format: uri
          example: "https://storage.googleapis.com/foxli-cdn/media/med_44a9bc8.jpg"
        content_type:
          type: string
          example: "image/jpeg"
        mime_type:
          type: string
          example: "image/jpeg"
        size_bytes:
          type: integer
          example: 1048576
        width:
          type: integer
          nullable: true
        height:
          type: integer
          nullable: true
        duration_s:
          type: number
          nullable: true

    AnalyticsOverview:
      type: object
      required:
        - kpis
        - daily_series
      properties:
        range:
          type: object
          properties:
            from:
              type: string
              format: date
            to:
              type: string
              format: date
            previous_from:
              type: string
              format: date
            previous_to:
              type: string
              format: date
        kpis:
          type: object
          properties:
            followers:
              type: integer
              example: 12500
            followers_change:
              type: integer
              example: 320
            impressions:
              type: integer
              example: 45200
            reach:
              type: integer
              example: 38100
            engagements:
              type: integer
              example: 3820
            engagement_rate:
              type: number
              example: 8.45
            posts_published:
              type: integer
              example: 24
            total_impressions:
              type: integer
              example: 45200
            total_engagements:
              type: integer
              example: 3820
            total_posts:
              type: integer
              example: 24
            avg_engagement_rate:
              type: number
              example: 8.45
        daily:
          type: array
          items:
            type: object
            properties:
              date:
                type: string
                format: date
                example: "2026-10-15"
              impressions:
                type: integer
                example: 1820
              engagements:
                type: integer
                example: 160
              followers:
                type: integer
                example: 12450
        daily_series:
          type: array
          items:
            type: object
            properties:
              date:
                type: string
                format: date
                example: "2026-10-15"
              impressions:
                type: integer
                example: 1820
              engagements:
                type: integer
                example: 160
              followers:
                type: integer
                example: 12450

    WebhookEndpoint:
      type: object
      required:
        - id
        - url
        - events
        - status
        - created_at
      properties:
        id:
          type: string
          example: "wh_78a1bc"
        url:
          type: string
          format: uri
          example: "https://agency.example.com/api/foxli-events"
        events:
          type: array
          items:
            type: string
          example: ["post.published", "post.failed"]
        status:
          type: string
          enum: [active, failing, disabled]
          example: "active"
        secret:
          type: string
          description: Signing secret displayed upon creation.
          example: "whsec_39f018b2c48d910a78129abf5c901234"
        created_at:
          type: string
          format: date-time
        consecutive_failures:
          type: integer
          example: 0
        last_delivery:
          type: object
          properties:
            code:
              type: integer
              example: 200
            at:
              type: string
              format: date-time

    WebhookPayload:
      type: object
      required:
        - id
        - type
        - created_at
        - workspace_id
        - data
      properties:
        id:
          type: string
          example: "evt_90f12c"
        type:
          type: string
          enum: [post.published, post.failed, post.partially_published, channel.disconnected, ping]
          example: "post.published"
        created_at:
          type: string
          format: date-time
          example: "2026-11-05T12:00:00Z"
        workspace_id:
          type: string
          example: "ws_brand_primary"
        data:
          type: object
          description: Event data. post.* events contain the serialized post; channel.disconnected contains the channel object.
