openapi: 3.0.3
info:
  title: BetTune API
  version: 1.0.0
  description: External API for BetTune match discovery and prediction management.
servers:
  - url: https://ovaccess.com/bet-tune-api/v1
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Sports
  - name: Matches
  - name: Prediction Filters
  - name: Predictions
paths:
  /sports:
    get:
      tags:
        - Sports
      summary: List available sports
      operationId: listSports
      responses:
        '200':
          description: Available sports.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SportsResponse'
              example:
                count: 1
                items:
                  - id: 1
                    name: football
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/RateLimitExceeded'
  /matches:
    get:
      tags:
        - Matches
      summary: List matches for one UTC date
      operationId: listMatches
      parameters:
        - name: date
          in: query
          required: true
          description: UTC date in `YYYY-MM-DD` format.
          schema:
            type: string
            format: date
          example: '2026-06-06'
        - name: sport
          in: query
          required: true
          description: Sport id. Currently only football is exposed by `/sports`.
          schema:
            type: integer
          example: 1
      responses:
        '200':
          description: Matches for the requested UTC date.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MatchesResponse'
        '400':
          description: Invalid query parameters.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                dateInvalid:
                  value:
                    code: date_invalid
                    message: 'Invalid or missing date. Expected format: YYYY-MM-DD'
                sportInvalid:
                  value:
                    code: sport_invalid
                    message: Invalid or missing sport
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/RateLimitExceeded'
  /prediction-filters:
    get:
      tags:
        - Prediction Filters
      summary: List prediction filters
      operationId: listPredictionFilters
      responses:
        '200':
          description: Prediction-based filters for the current API token user.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PredictionFiltersResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/RateLimitExceeded'
  /predictions/search:
    post:
      tags:
        - Predictions
      summary: Search existing predictions
      operationId: searchPredictions
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SearchPredictionsRequest'
            example:
              filterId: 11583
              matchIds:
                - 1611243
                - 1611244
      responses:
        '200':
          description: Existing predictions for requested matches.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PredictionsResponse'
        '400':
          $ref: '#/components/responses/ValidationError'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/RateLimitExceeded'
  /prediction-filters/{filterId}/matches/{matchId}/prediction:
    put:
      tags:
        - Predictions
      summary: Create or update prediction odds
      operationId: putPrediction
      parameters:
        - $ref: '#/components/parameters/FilterId'
        - $ref: '#/components/parameters/MatchId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PutPredictionRequest'
            example:
              odds: '2.15'
      responses:
        '200':
          description: Created or updated prediction.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Prediction'
        '400':
          $ref: '#/components/responses/ValidationError'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/RateLimitExceeded'
    delete:
      tags:
        - Predictions
      summary: Delete prediction
      operationId: deletePrediction
      parameters:
        - $ref: '#/components/parameters/FilterId'
        - $ref: '#/components/parameters/MatchId'
      responses:
        '204':
          description: Prediction deleted. The endpoint is idempotent.
        '400':
          $ref: '#/components/responses/ValidationError'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/RateLimitExceeded'
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: BetTune API token
  parameters:
    FilterId:
      name: filterId
      in: path
      required: true
      schema:
        type: integer
      example: 11583
    MatchId:
      name: matchId
      in: path
      required: true
      schema:
        type: integer
      example: 1611243
  responses:
    Unauthorized:
      description: Missing or invalid API token.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            missingToken:
              value:
                code: missing_token
                message: No token provided
            invalidToken:
              value:
                code: invalid_token
                message: Invalid token
    Forbidden:
      description: The current user cannot access this resource.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            code: pro_subscription_required
            message: Prediction-based filters are available only for PRO subscription
    NotFound:
      description: Filter or match not found.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            filterNotFound:
              value:
                code: filter_not_found
                message: Filter not found
            matchNotFound:
              value:
                code: match_not_found
                message: Match not found
    ValidationError:
      description: Validation error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            invalidJsonBody:
              value:
                code: invalid_json_body
                message: Invalid JSON body
            oddsInvalid:
              value:
                code: odds_invalid
                message: Odds is required and must be at least 1.01
            matchIdsInvalid:
              value:
                code: match_ids_invalid
                message: matchIds is required and must contain up to 500 numeric ids
            filterNotPredictionBased:
              value:
                code: filter_not_prediction_based
                message: Filter is not prediction-based
            matchSportMismatch:
              value:
                code: match_sport_mismatch
                message: Match sport does not match filter sport
    RateLimitExceeded:
      description: Rate limit exceeded.
      headers:
        Retry-After:
          schema:
            type: string
          example: '60'
        X-RateLimit-Limit:
          schema:
            type: string
          example: '60'
        X-RateLimit-Window:
          schema:
            type: string
          example: '60'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            code: rate_limit_exceeded
            message: Rate limit exceeded
  schemas:
    ErrorResponse:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
        message:
          type: string
    SportsResponse:
      type: object
      required:
        - count
        - items
      properties:
        count:
          type: integer
        items:
          type: array
          items:
            $ref: '#/components/schemas/Sport'
    Sport:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: integer
          example: 1
        name:
          type: string
          example: football
    MatchesResponse:
      type: object
      required:
        - date
        - count
        - items
      properties:
        date:
          type: string
          format: date
          example: '2026-06-06'
        count:
          type: integer
        items:
          type: array
          items:
            $ref: '#/components/schemas/Match'
    Match:
      type: object
      required:
        - id
        - date
        - finished
        - score
        - country
        - tournament
        - season
        - home
        - away
      properties:
        id:
          type: integer
          example: 1611243
        date:
          type: string
          format: date-time
          example: '2026-06-06T18:00:00+00:00'
        finished:
          type: boolean
          example: false
        score:
          $ref: '#/components/schemas/Score'
        country:
          $ref: '#/components/schemas/IdName'
        tournament:
          $ref: '#/components/schemas/IdName'
        season:
          $ref: '#/components/schemas/IdName'
        home:
          $ref: '#/components/schemas/IdName'
        away:
          $ref: '#/components/schemas/IdName'
    Score:
      type: object
      required:
        - home
        - away
      properties:
        home:
          type: integer
          nullable: true
          example: null
        away:
          type: integer
          nullable: true
          example: null
    IdName:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: integer
        name:
          type: string
    PredictionFiltersResponse:
      type: object
      required:
        - count
        - items
      properties:
        count:
          type: integer
        items:
          type: array
          items:
            $ref: '#/components/schemas/PredictionFilter'
    PredictionFilter:
      type: object
      required:
        - id
        - name
        - sport
        - betType
        - status
      properties:
        id:
          type: integer
          example: 11583
        name:
          type: string
          example: Manual football
        sport:
          $ref: '#/components/schemas/Sport'
        betType:
          type: string
          example: Home
        status:
          type: string
          enum:
            - disabled
            - approved
          example: approved
    SearchPredictionsRequest:
      type: object
      required:
        - filterId
        - matchIds
      properties:
        filterId:
          type: integer
          example: 11583
        matchIds:
          type: array
          minItems: 1
          maxItems: 500
          items:
            type: integer
          example:
            - 1611243
            - 1611244
    PutPredictionRequest:
      type: object
      required:
        - odds
      properties:
        odds:
          oneOf:
            - type: string
            - type: number
          example: '2.15'
    PredictionsResponse:
      type: object
      required:
        - count
        - items
      properties:
        count:
          type: integer
        items:
          type: array
          items:
            $ref: '#/components/schemas/Prediction'
    Prediction:
      type: object
      required:
        - id
        - filterId
        - matchId
        - odds
        - source
        - createdAt
        - updatedAt
      properties:
        id:
          type: integer
          example: 10
        filterId:
          type: integer
          example: 11583
        matchId:
          type: integer
          example: 1611243
        odds:
          type: string
          nullable: true
          example: '2.150000'
        source:
          type: string
          enum:
            - api
            - ui
          example: api
        createdAt:
          type: string
          format: date-time
          example: '2026-06-06T12:00:00+00:00'
        updatedAt:
          type: string
          format: date-time
          example: '2026-06-06T12:05:00+00:00'
