#@ load("openapi.lib.yml", "response", "response_with_accepted", "reference", "type", "array")

paths:
  /collections/{collection_name}/shards/{shard_id}/snapshots/upload:
    post:
      tags:
        - Snapshots
      summary: Recover shard from an uploaded snapshot
      description: Recover shard of a local collection from an uploaded snapshot. This will overwrite any data, stored on this node, for the collection shard.
      operationId: recover_shard_from_uploaded_snapshot
      parameters:
        - name: collection_name
          in: path
          description: Name of the collection
          required: true
          schema:
            type: string
        - name: shard_id
          in: path
          description: Id of the shard to recover
          required: true
          schema:
              type: integer
        - name: wait
          in: query
          description: "If true, wait for changes to actually happen. If false - let changes happen in background. Default is true."
          required: false
          schema:
            type: boolean
        - name: priority
          in: query
          description: "Defines source of truth for snapshot recovery"
          required: false
          schema:
            $ref: "#/components/schemas/SnapshotPriority"
        - name: checksum
          in: query
          description: "Optional SHA256 checksum to verify snapshot integrity before recovery."
          required: false
          schema:
            type: string
      requestBody:
        description: Snapshot to recover from
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                snapshot:
                  type: string
                  format: binary
      responses: #@ response_with_accepted(type("boolean"))
  /collections/{collection_name}/shards/{shard_id}/snapshots/recover:
    put:
      tags:
        - Snapshots
      summary: Recover from a snapshot
      description: Recover shard of a local collection data from a snapshot. This will overwrite any data, stored in this shard, for the collection.
      operationId: recover_shard_from_snapshot
      parameters:
        - name: collection_name
          in: path
          description: Name of the collection
          required: true
          schema:
            type: string
        - name: shard_id
          in: path
          description: Id of the shard to recover
          required: true
          schema:
            type: integer
        - name: wait
          in: query
          description: "If true, wait for changes to actually happen. If false - let changes happen in background. Default is true."
          required: false
          schema:
            type: boolean
      requestBody:
        description: Snapshot to recover from
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ShardSnapshotRecover"
      responses: #@ response_with_accepted(type("boolean"))

  /collections/{collection_name}/shards/{shard_id}/snapshots:
    get:
      tags:
        - Snapshots
      summary: List shards snapshots for a collection
      description: Get list of snapshots for a shard of a collection
      operationId: list_shard_snapshots
      parameters:
        - name: collection_name
          in: path
          description: Name of the collection
          required: true
          schema:
            type: string
        - name: shard_id
          in: path
          description: Id of the shard
          required: true
          schema:
              type: integer
      responses: #@ response(array(reference("SnapshotDescription")))

    post:
      tags:
        - Snapshots
      summary: Create shard snapshot
      description: Create new snapshot of a shard for a collection
      operationId: create_shard_snapshot
      parameters:
        - name: collection_name
          in: path
          description: Name of the collection for which to create a snapshot
          required: true
          schema:
            type: string
        - name: shard_id
          in: path
          description: Id of the shard
          required: true
          schema:
            type: integer
        - name: wait
          in: query
          description: "If true, wait for changes to actually happen. If false - let changes happen in background. Default is true."
          required: false
          schema:
            type: boolean
      responses: #@ response_with_accepted(reference("SnapshotDescription"))

  /collections/{collection_name}/shards/{shard_id}/snapshots/{snapshot_name}:
    delete:
      tags:
        - Snapshots
      summary: Delete shard snapshot
      description: Delete snapshot of a shard for a collection
      operationId: delete_shard_snapshot
      parameters:
        - name: collection_name
          in: path
          description: Name of the collection for which to delete a snapshot
          required: true
          schema:
            type: string
        - name: shard_id
          in: path
          description: Id of the shard
          required: true
          schema:
              type: integer
        - name: snapshot_name
          in: path
          description: Name of the snapshot to delete
          required: true
          schema:
            type: string
        - name: wait
          in: query
          description: "If true, wait for changes to actually happen. If false - let changes happen in background. Default is true."
          required: false
          schema:
            type: boolean
      responses: #@ response_with_accepted(type("boolean"))
    get:
      tags:
        - Snapshots
      summary: Download collection snapshot
      description: Download specified snapshot of a shard from a collection as a file
      operationId: get_shard_snapshot
      parameters:
        - name: collection_name
          in: path
          description: Name of the collection
          required: true
          schema:
            type: string
        - name: shard_id
          in: path
          description: Id of the shard
          required: true
          schema:
              type: integer
        - name: snapshot_name
          in: path
          description: Name of the snapshot to download
          required: true
          schema:
            type: string

      responses:
        default:
          description: error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        4XX:
          description: error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        '200':
          description: Snapshot file
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary
