

openapi: 3.0.0
info:
  title: Billing API
  version: 1.0.0
  description: API for accessing billing data and managing invoices, subscriptions, and customers

servers:
  - url: /api/v1

components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

  schemas:
    Invoice:
      type: object
      properties:
        id:
          type: integer
        invoice_number:
          type: string
        customer:
          $ref: '#/components/schemas/Customer'
        total_amount:
          type: number
          format: float
        currency:
          type: string
        status:
          type: string
          enum: [draft, sent, paid, cancelled]
        issue_date:
          type: string
          format: date-time
        due_date:
          type: string
          format: date-time
        paid_at:
          type: string
          format: date-time
          nullable: true
        items:
          type: array
          items:
            $ref: '#/components/schemas/InvoiceItem'

paths:
  /auth/token:
    post:
      summary: Generate API token
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                email:
                  type: string
                password:
                  type: string
                device_name:
                  type: string
      responses:
        200:
          description: Token generated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  token:
                    type: string
                  user:
                    type: object

  /invoices:
    get:
      summary: List invoices
      security:
        - bearerAuth: []
      parameters:
        - name: status
          in: query
          schema:
            type: string
        - name: customer_id
          in: query
          schema:
            type: integer
        - name: from_date
          in: query
          schema:
            type: string
            format: date
        - name: to_date
          in: query
          schema:
            type: string
            format: date
      responses:
        200:
          description: List of invoices
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Invoice'
                  links:
                    type: object
                  meta:
                    type: object

    post:
      summary: Create new invoice
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                customer_id:
                  type: integer
                issue_date:
                  type: string
                  format: date
                due_date:
                  type: string
                  format: date
                items:
                  type: array
                  items:
                    type: object
                    properties:
                      description:
                        type: string
                      quantity:
                        type: number
                      price:
                        type: number
      responses:
        201:
          description: Invoice created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Invoice'