openapi: 3.0.3
info:
  title: Provjera posrednika API
  version: "1.0.1"
  description: |
    Public JSON API for checking certified e-invoicing intermediaries.

    Authentication is required for all endpoints via `X-API-Key`.
servers:
  - url: /api/v1

tags:
  - name: Check
    description: Validate OIB/GLN and retrieve intermediary details.
  - name: Intermediaries
    description: Search and browse intermediaries.
  - name: Stats
    description: Basic service statistics.

components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
  schemas:
    Envelope:
      type: object
      required: [success, data, error, meta]
      properties:
        success:
          type: boolean
        data:
          nullable: true
        error:
          nullable: true
          $ref: '#/components/schemas/Error'
        meta:
          $ref: '#/components/schemas/Meta'
    Meta:
      type: object
      required: [request_id, timestamp, version]
      properties:
        request_id:
          type: string
          example: "a1b2c3d4e5f67890"
        timestamp:
          type: string
          format: date-time
        version:
          type: string
          example: "v1"
    Error:
      type: object
      required: [code, message, request_id]
      properties:
        code:
          type: string
          example: "unauthorized"
        message:
          type: string
          example: "Unauthorized."
        request_id:
          type: string
          example: "a1b2c3d4e5f67890"
    CheckData:
      type: object
      required: [found, certified, broker, health, ams, meta]
      properties:
        found:
          type: boolean
        certified:
          type: boolean
        broker:
          nullable: true
          $ref: '#/components/schemas/Broker'
        health:
          type: object
          properties:
            status:
              type: string
            online:
              nullable: true
              type: boolean
        ams:
          type: object
          properties:
            ams_available:
              type: boolean
            mps_url:
              type: string
            mps_confirmed:
              nullable: true
              type: boolean
        meta:
          type: object
          properties:
            updated_at:
              type: string
            timezone:
              type: string
    Broker:
      type: object
      properties:
        name:
          type: string
        oib:
          type: string
        status:
          type: string
        services:
          type: object
          properties:
            eracun:
              type: boolean
            eizvjestavanje:
              type: boolean
            mps:
              type: boolean
            ams:
              type: boolean
        website:
          type: string
        pricing:
          type: object
          properties:
            url:
              type: string
            text:
              type: string
        contacts:
          type: object
          additionalProperties: true

  responses:
    ErrorResponse:
      description: Error
      content:
        application/json:
          schema:
            allOf:
              - $ref: '#/components/schemas/Envelope'
              - type: object
                properties:
                  success:
                    example: false
                  data:
                    example: null
                  error:
                    $ref: '#/components/schemas/Error'

security:
  - ApiKeyAuth: []

paths:
  /check:
    get:
      tags: [Check]
      summary: Check intermediary by OIB or GLN
      parameters:
        - in: query
          name: type
          required: false
          schema:
            type: string
            enum: [OIB, GLN]
          description: Identifier type (default OIB)
        - in: query
          name: id
          required: false
          schema:
            type: string
          description: Digits-only identifier
        - in: query
          name: oib
          required: false
          schema:
            type: string
          description: Convenience alias for OIB
        - in: query
          name: gln
          required: false
          schema:
            type: string
          description: Convenience alias for GLN
        - in: query
          name: idType
          required: false
          deprecated: true
          schema:
            type: string
            enum: [OIB, GLN]
        - in: query
          name: identifier
          required: false
          deprecated: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Envelope'
                  - type: object
                    properties:
                      data:
                        $ref: '#/components/schemas/CheckData'
        '400':
          $ref: '#/components/responses/ErrorResponse'
        '401':
          $ref: '#/components/responses/ErrorResponse'
        '403':
          $ref: '#/components/responses/ErrorResponse'
        '429':
          $ref: '#/components/responses/ErrorResponse'
        '503':
          $ref: '#/components/responses/ErrorResponse'
    post:
      tags: [Check]
      summary: Check intermediary by OIB or GLN (JSON body)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [idType, identifier]
              properties:
                idType:
                  type: string
                  enum: [OIB, GLN]
                identifier:
                  type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Envelope'
                  - type: object
                    properties:
                      data:
                        $ref: '#/components/schemas/CheckData'
        '400':
          $ref: '#/components/responses/ErrorResponse'
        '401':
          $ref: '#/components/responses/ErrorResponse'
        '403':
          $ref: '#/components/responses/ErrorResponse'
        '429':
          $ref: '#/components/responses/ErrorResponse'
        '503':
          $ref: '#/components/responses/ErrorResponse'

  /intermediaries:
    get:
      tags: [Intermediaries]
      summary: Search intermediaries
      parameters:
        - in: query
          name: q
          schema:
            type: string
        - in: query
          name: service
          schema:
            type: string
            enum: [eracun, eizvjestavanje, mps, ams]
        - in: query
          name: page
          schema:
            type: integer
            minimum: 1
            default: 1
        - in: query
          name: per_page
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 25
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Envelope'
        '400':
          $ref: '#/components/responses/ErrorResponse'
        '401':
          $ref: '#/components/responses/ErrorResponse'
        '403':
          $ref: '#/components/responses/ErrorResponse'
        '429':
          $ref: '#/components/responses/ErrorResponse'
        '503':
          $ref: '#/components/responses/ErrorResponse'

  /stats:
    get:
      tags: [Stats]
      summary: API stats
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Envelope'
        '401':
          $ref: '#/components/responses/ErrorResponse'
        '403':
          $ref: '#/components/responses/ErrorResponse'
        '429':
          $ref: '#/components/responses/ErrorResponse'
        '503':
          $ref: '#/components/responses/ErrorResponse'
