"/admin/tv/channel":
    post:
        tags: [Channels]
        operationId: createChannel
        summary: Create a TV channel
        description: Creates a TV channel.
        requestBody:
            required: true
            content:
                application/json:
                    schema:
                        type: object
                        required: [name, title, description]
                        properties:
                            name: { type: string }
                            title: { type: string }
                            description: { type: string }
        responses:
            "200":
                description: Created channel.
                content:
                    application/json:
                        schema: { $ref: "../components/schemas/Channel.yaml" }
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
        x-access-policies: [Admin]
        x-scopes: ["media:write", "admin:all"]
    put:
        tags: [Channels]
        operationId: updateChannel
        summary: Update a TV channel
        description: Updates a TV channel. The id is supplied in the body.
        requestBody:
            required: true
            content:
                application/json:
                    schema:
                        type: object
                        required: [id]
                        properties:
                            id: { type: string }
                        additionalProperties: true
        responses:
            "200":
                description: Updated channel.
                content:
                    application/json:
                        schema: { $ref: "../components/schemas/Channel.yaml" }
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
        x-access-policies: [Admin]
        x-scopes: ["media:write", "admin:all"]

"/admin/tv/channel/{channelId}":
    parameters:
        - in: path
          name: channelId
          required: true
          schema: { type: string }
    delete:
        tags: [Channels]
        operationId: deleteChannel
        summary: Delete a channel
        description: Deletes a TV channel by id.
        responses:
            "200":
                description: Channel deleted.
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
            "404":
                description: No channel with this id.
                content:
                    application/json:
                        schema: { $ref: "../admin-api.yaml#/components/schemas/Error" }
        x-access-policies: [Admin]
        x-scopes: ["media:write", "admin:all"]
    get:
        tags: [Channels]
        operationId: getChannel
        summary: Fetch a channel
        description: Returns a channel by id.
        responses:
            "200":
                description: Channel record.
                content:
                    application/json:
                        schema: { $ref: "../components/schemas/Channel.yaml" }
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
            "404":
                description: No channel with this id.
                content:
                    application/json:
                        schema: { $ref: "../admin-api.yaml#/components/schemas/Error" }
        x-access-policies: [Admin]
        x-scopes: ["media:read", "admin:all"]

"/admin/tv/Channels":
    get:
        tags: [Channels]
        operationId: getChannels
        summary: List all channels
        description: Returns every TV channel.
        responses:
            "200":
                description: Array of channels.
                content:
                    application/json:
                        schema:
                            type: array
                            items: { $ref: "../components/schemas/Channel.yaml" }
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
        x-access-policies: [Admin]
        x-scopes: ["media:read", "admin:all"]

"/admin/tv/stream":
    post:
        tags: [Channels]
        operationId: addStreamToChannel
        summary: Add a stream to a channel
        description: Adds a stream entry to an existing channel.
        requestBody:
            required: true
            content:
                application/json:
                    schema:
                        type: object
                        required: [channelId, stream]
                        properties:
                            channelId: { type: string }
                            stream:
                                type: object
                                description: "`StreamData` payload (see `LegacySchemas.StreamData`)."
                                properties:
                                    uri: { type: string, format: uri }
                                    isAvailable: { type: boolean }
                                    type: { type: string }
                                additionalProperties: true
        responses:
            "200":
                description: Updated channel.
                content:
                    application/json:
                        schema: { $ref: "../components/schemas/Channel.yaml" }
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
        x-access-policies: [Admin]
        x-scopes: ["media:write", "admin:all"]

"/admin/tv/stream/{channelId}/{streamIndex}":
    parameters:
        - in: path
          name: channelId
          required: true
          schema: { type: string }
        - in: path
          name: streamIndex
          required: true
          schema: { type: integer }
          description: Zero-based index of the stream within the channel's stream array.
    delete:
        tags: [Channels]
        operationId: deleteStreamFromChannel
        summary: Remove a stream from a channel
        description: Removes the stream at the given index from a channel.
        responses:
            "200":
                description: Stream removed.
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
            "404":
                description: No channel or no stream at that index.
                content:
                    application/json:
                        schema: { $ref: "../admin-api.yaml#/components/schemas/Error" }
        x-access-policies: [Admin]
        x-scopes: ["media:write", "admin:all"]

"/admin/tv/channel_query/{name}":
    parameters:
        - in: path
          name: name
          required: true
          schema: { type: string }
          description: Channel-query name.
    get:
        tags: [Channels]
        operationId: getChannelQueryValues
        summary: Channel query values
        description: |
            Returns channel query values by name. The query name is one of a small set of
            named queries baked into `api/src/Channels.ts`; values are the live query
            results expanded into stream entries.
        responses:
            "200":
                description: Query values.
                content:
                    application/json:
                        schema:
                            type: object
                            properties:
                                name: { type: string }
                                streams:
                                    type: array
                                    items:
                                        type: object
                                        additionalProperties: true
                                count: { type: integer }
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
        x-access-policies: [Admin]
        x-scopes: ["media:read", "admin:all"]

"/admin/tv/channel_group":
    post:
        tags: [Channels]
        operationId: createChannelGroup
        summary: Create a channel group
        description: Creates a channel group — a collection of channels organized for the Bigscreen TV UI.
        requestBody:
            required: true
            content:
                application/json:
                    schema:
                        type: object
                        required: [name, title]
                        properties:
                            name: { type: string, description: URL slug. }
                            title: { type: string }
                            channelIds:
                                type: array
                                items: { type: string }
                            isPublished: { type: boolean, default: true }
                            imageUrl: { type: string, format: uri }
        responses:
            "200":
                description: Created channel group.
                content:
                    application/json:
                        schema: { $ref: "../components/schemas/ChannelGroup.yaml" }
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
        x-access-policies: [Admin]
        x-scopes: ["media:write", "admin:all"]
    put:
        tags: [Channels]
        operationId: updateChannelGroup
        summary: Update a channel group
        description: Updates a channel group. The id is supplied in the body.
        requestBody:
            required: true
            content:
                application/json:
                    schema:
                        type: object
                        required: [id]
                        properties:
                            id: { type: string }
                        additionalProperties: true
        responses:
            "200":
                description: Updated channel group.
                content:
                    application/json:
                        schema: { $ref: "../components/schemas/ChannelGroup.yaml" }
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
        x-access-policies: [Admin]
        x-scopes: ["media:write", "admin:all"]

"/admin/tv/channel_group/{channelGroupId}":
    parameters:
        - in: path
          name: channelGroupId
          required: true
          schema: { type: string }
    get:
        tags: [Channels]
        operationId: getChannelGroup
        summary: Fetch a channel group
        description: Returns a channel group by id.
        responses:
            "200":
                description: Channel group record.
                content:
                    application/json:
                        schema: { $ref: "../components/schemas/ChannelGroup.yaml" }
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
            "404":
                description: No channel group with this id.
                content:
                    application/json:
                        schema: { $ref: "../admin-api.yaml#/components/schemas/Error" }
        x-access-policies: [Admin]
        x-scopes: ["media:read", "admin:all"]
    delete:
        tags: [Channels]
        operationId: deleteChannelGroup
        summary: Delete a channel group
        description: Deletes a channel group by id.
        responses:
            "200":
                description: Channel group deleted.
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
            "404":
                description: No channel group with this id.
                content:
                    application/json:
                        schema: { $ref: "../admin-api.yaml#/components/schemas/Error" }
        x-access-policies: [Admin]
        x-scopes: ["media:write", "admin:all"]

"/admin/tv/rebuild_channel_group/{channelGroupId}":
    parameters:
        - in: path
          name: channelGroupId
          required: true
          schema: { type: string }
    get:
        tags: [Channels]
        operationId: rebuildChannelGroup
        summary: Rebuild / refresh a channel group
        description: Rebuilds the channel group's underlying texture/cached state.
        responses:
            "200":
                description: Rebuild summary.
                content:
                    application/json:
                        schema:
                            type: object
                            properties:
                                channelGroupId: { type: string }
                                texturesRebuilt: { type: integer }
                                channelsProcessed: { type: integer }
                                durationMs: { type: integer }
                                errors:
                                    type: array
                                    items: { type: string }
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
        x-access-policies: [Admin]
        x-scopes: ["media:read", "admin:all"]

"/admin/tv/channel_groups":
    get:
        tags: [Channels]
        operationId: getChannelGroups
        summary: List all channel groups
        description: Returns every channel group.
        responses:
            "200":
                description: Array of channel groups.
                content:
                    application/json:
                        schema:
                            type: array
                            items: { $ref: "../components/schemas/ChannelGroup.yaml" }
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
        x-access-policies: [Admin]
        x-scopes: ["media:read", "admin:all"]
