openapi: 3.0.3
info:
  title: eCom01 Petar Agent API
  version: 1.0.0
servers:
  - url: https://admin.ecom01.rs/api
security:
  - bearerAuth: []
paths:
  /leads:
    get:
      summary: List leads
      security:
        - bearerAuth: [leads:read]
      parameters:
        - { name: q, in: query, schema: { type: string } }
        - { name: status, in: query, schema: { type: string } }
        - { name: source, in: query, schema: { type: string } }
        - { name: created_from, in: query, schema: { type: string, format: date-time } }
        - { name: created_to, in: query, schema: { type: string, format: date-time } }
        - { name: assigned_to, in: query, schema: { type: integer } }
        - { name: page, in: query, schema: { type: integer, minimum: 1 } }
        - { name: per_page, in: query, schema: { type: integer, minimum: 1, maximum: 100 } }
      responses:
        "200":
          description: Paginated leads
  /leads/{id}:
    get:
      summary: Get lead
      security:
        - bearerAuth: [leads:read]
      parameters:
        - { name: id, in: path, required: true, schema: { type: integer } }
      responses:
        "200":
          description: Lead detail
  /leads/summary:
    get:
      summary: Lead counters for heartbeat
      security:
        - bearerAuth: [leads:read]
      responses:
        "200":
          description: Summary counters
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      new_24h: { type: integer }
                      missing_contact: { type: integer }
                      high_potential_no_email: { type: integer }
                      needs_followup: { type: integer }
  /leads/alerts:
    get:
      summary: Lead alerts since timestamp
      security:
        - bearerAuth: [leads:read]
      parameters:
        - { name: since, in: query, schema: { type: string, format: date-time } }
      responses:
        "200":
          description: Alert list for Telegram notifications
  /blog/posts:
    post:
      summary: Create blog post
      security:
        - bearerAuth: [blog:write]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/BlogPostInput"
          multipart/form-data:
            schema:
              allOf:
                - $ref: "#/components/schemas/BlogPostInput"
                - type: object
                  properties:
                    hero_image:
                      type: string
                      format: binary
      responses:
        "201":
          description: Blog post created
        "422":
          description: Validation error
  /blog/posts/{id}:
    get:
      summary: Get draft/preview blog post
      security:
        - bearerAuth: [blog:write]
      parameters:
        - { name: id, in: path, required: true, schema: { type: integer } }
      responses:
        "200":
          description: Blog post detail
    patch:
      summary: Update, publish, or schedule blog post
      security:
        - bearerAuth: [blog:write]
      parameters:
        - { name: id, in: path, required: true, schema: { type: integer } }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/BlogPostInput"
          multipart/form-data:
            schema:
              allOf:
                - $ref: "#/components/schemas/BlogPostInput"
                - type: object
                  properties:
                    hero_image:
                      type: string
                      format: binary
      responses:
        "200":
          description: Blog post updated
  /blog/upload:
    post:
      summary: Upload blog image
      security:
        - bearerAuth: [blog:write]
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required: [image]
              properties:
                image:
                  type: string
                  format: binary
      responses:
        "201":
          description: Uploaded image URL
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: Sanctum
  schemas:
    BlogPostInput:
      type: object
      properties:
        title: { type: string }
        slug: { type: string, nullable: true }
        excerpt: { type: string, nullable: true }
        body_markdown: { type: string, nullable: true }
        body_html: { type: string, nullable: true }
        status:
          type: string
          enum: [draft, scheduled, published]
        scheduled_at: { type: string, format: date-time, nullable: true }
        published_at: { type: string, format: date-time, nullable: true }
        tags:
          type: array
          items: { type: string }
        image_url: { type: string, format: uri, nullable: true }
        hero_image_path: { type: string, nullable: true }
        seo:
          type: object
          properties:
            meta_title: { type: string, nullable: true }
            meta_description: { type: string, nullable: true }
        canonical_url: { type: string, format: uri, nullable: true }
