swagger: '2.0'

info:
    title: MiroTalk SFU API
    description: API description for external applications that integrate with MiroTalk SFU.
    version: 1.0.1

basePath: /api/v1

schemes:
    - https
    - http

paths:
    /stats:
        get:
            tags:
                - 'stats'
            summary: 'Get stats'
            description: 'Get meetings'
            produces:
                - 'application/json'
            security:
                - secretApiKey: []
            responses:
                '200':
                    description: 'Get Stats done'
                    schema:
                        $ref: '#/definitions/StatsResponse'
                '403':
                    description: 'Unauthorized!'

    /meetings:
        get:
            tags:
                - 'meetings'
            summary: 'Get meetings'
            description: 'Get meetings'
            produces:
                - 'application/json'
            security:
                - secretApiKey: []
            responses:
                '200':
                    description: 'Get Meetings done'
                    schema:
                        $ref: '#/definitions/MeetingsResponse'
                '403':
                    description: 'Unauthorized!'
    /meeting:
        post:
            tags:
                - 'meeting'
            summary: 'Create meeting'
            description: 'Create meeting'
            consumes:
                - 'application/json'
            produces:
                - 'application/json'
            security:
                - secretApiKey: []
            responses:
                '200':
                    description: 'Meeting created'
                    schema:
                        $ref: '#/definitions/MeetingResponse'
                '403':
                    description: 'Unauthorized!'
    /meeting/{room}:
        delete:
            tags:
                - 'meeting'
            summary: 'End meeting'
            description: 'End an active meeting by room name. All connected peers will be disconnected and redirected to the specified URL or home page.'
            parameters:
                - in: path
                  name: room
                  required: true
                  type: string
                  description: 'The room name/ID of the meeting to end'
                - in: body
                  name: body
                  required: false
                  description: 'Optional body with redirect URL'
                  schema:
                      $ref: '#/definitions/EndMeetingRequest'
            consumes:
                - 'application/json'
            produces:
                - 'application/json'
            security:
                - secretApiKey: []
            responses:
                '200':
                    description: 'Meeting ended successfully'
                    schema:
                        $ref: '#/definitions/EndMeetingResponse'
                '403':
                    description: 'Unauthorized!'
                '404':
                    description: 'Room not found'
    /join:
        post:
            tags:
                - 'join'
            summary: 'Create direct join'
            description: 'Create join'
            parameters:
                - in: body
                  name: Join
                  description: Custom Join URL.
                  schema:
                      $ref: '#/definitions/JoinRequest'
            consumes:
                - 'application/json'
            produces:
                - 'application/json'
            security:
                - secretApiKey: []
            responses:
                '200':
                    description: 'Direct join created'
                    schema:
                        $ref: '#/definitions/JoinResponse'
                '403':
                    description: 'Unauthorized!'
    /token:
        post:
            tags:
                - 'token'
            summary: 'Get token'
            description: 'Get token'
            parameters:
                - in: body
                  name: token
                  description: Custom Token.
                  schema:
                      $ref: '#/definitions/TokenRequest'
            consumes:
                - 'application/json'
            produces:
                - 'application/json'
            security:
                - secretApiKey: []
            responses:
                '200':
                    description: 'Get token done'
                    schema:
                        $ref: '#/definitions/TokenResponse'
                '403':
                    description: 'Unauthorized!'

securityDefinitions:
    secretApiKey:
        type: 'apiKey'
        name: 'authorization'
        in: 'header'
        description: 'Format like this: authorization: {API_KEY_SECRET}'

definitions:
    StatsResponse:
        type: object
        properties:
            success:
                type: boolean
            timestamp:
                type: string
                format: date-time
                example: '2025-12-21T12:00:00Z'
            totalRooms:
                type: integer
            totalPeers:
                type: integer
    MeetingsResponse:
        type: object
        properties:
            meetings:
                type: array
                items:
                    $ref: '#/definitions/Meeting'
    MeetingResponse:
        type: 'object'
        properties:
            meeting:
                type: string
    JoinRequest:
        type: object
        properties:
            room:
                type: string
                default: 'test'
            roomPassword:
                type: ['boolean', 'string'] # Allow boolean or string type
                default: false
            name:
                type: string
                default: 'mirotalksfu'
            avatar:
                type: ['boolean', 'string'] # Allow boolean or string type
                default: false
            audio:
                type: boolean
                default: false
            video:
                type: boolean
                default: false
            screen:
                type: boolean
                default: false
            chat:
                type: boolean
                default: false
            hide:
                type: boolean
                default: false
            notify:
                type: boolean
                default: false
            duration:
                type: string
                default: 'unlimited'
            token:
                $ref: '#/definitions/TokenRequest'
    TokenRequest:
        type: object
        properties:
            username:
                type: string
                default: 'username'
            password:
                type: string
                default: 'password'
            presenter:
                type: boolean
                default: true
            expire:
                type: string
                default: '1h'
    EndMeetingRequest:
        type: object
        properties:
            redirect:
                type: string
                description: 'URL to redirect peers to after the meeting ends. If empty, peers are redirected to the home page.'
                default: ''
    EndMeetingResponse:
        type: 'object'
        properties:
            success:
                type: boolean
            message:
                type: string
            room:
                type: string
    JoinResponse:
        type: 'object'
        properties:
            join:
                type: string
    TokenResponse:
        type: 'object'
        properties:
            token:
                type: string
    Peer:
        type: object
        properties:
            name:
                type: string
            avatar:
                type: string
            presenter:
                type: boolean
            video:
                type: boolean
            audio:
                type: boolean
            screen:
                type: boolean
            hand:
                type: boolean
            os:
                type: string
            browser:
                type: string

    Meeting:
        type: object
        properties:
            roomId:
                type: string
            peers:
                type: array
                items:
                    $ref: '#/definitions/Peer'
