openapi: 3.1.0
info:
  title: Api
  version: 0.1.0
  description: StreamHub API specification
servers:
  - url: /api
    description: Base API path
tags:
  - name: health
    description: Health operations
  - name: admin
    description: Admin operations
paths:
  /healthz:
    get:
      operationId: healthCheck
      tags: [health]
      summary: Health check
      description: Returns server health status
      responses:
        "200":
          description: Healthy
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/HealthStatus"
  /admin/login:
    post:
      operationId: adminLogin
      tags: [admin]
      summary: Admin login
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AdminLoginRequest"
      responses:
        "200":
          description: Login successful
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AdminLoginResponse"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
  /admin/ads:
    get:
      operationId: getAdSettings
      tags: [admin]
      summary: Get all ad settings
      security:
        - AdminToken: []
      responses:
        "200":
          description: Ad settings
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AdSettingsResponse"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
    put:
      operationId: updateAdSettings
      tags: [admin]
      summary: Update ad settings
      security:
        - AdminToken: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AdSettings"
      responses:
        "200":
          description: Updated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AdSettingsResponse"
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
components:
  securitySchemes:
    AdminToken:
      type: http
      scheme: bearer
  schemas:
    HealthStatus:
      type: object
      properties:
        status:
          type: string
      required:
        - status
    AdminLoginRequest:
      type: object
      properties:
        password:
          type: string
      required:
        - password
    AdminLoginResponse:
      type: object
      properties:
        token:
          type: string
        success:
          type: boolean
      required:
        - token
        - success
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
      required:
        - error
    AdSlot:
      type: object
      properties:
        enabled:
          type: boolean
        type:
          type: string
          enum: [banner, video, interstitial, native, script, adsense, custom]
        code:
          type: string
          description: Raw ad code / script
        position:
          type: string
          enum: [top, bottom, sidebar, before-content, after-content, overlay, in-feed]
        label:
          type: string
      required:
        - enabled
        - type
        - code
        - position
        - label
    AdSettings:
      type: object
      properties:
        slots:
          type: array
          items:
            $ref: "#/components/schemas/AdSlot"
        globalScript:
          type: string
          description: Global ad script injected in head
        adsensePublisherId:
          type: string
        enabled:
          type: boolean
      required:
        - slots
        - enabled
    AdSettingsResponse:
      type: object
      properties:
        data:
          $ref: "#/components/schemas/AdSettings"
      required:
        - data
