///
/// Copyright (c) 2022 Dropbox, Inc. All rights reserved.
///

import Foundation

// The case string below must match those created by ReconnectionHelpers+Handwritten.swift using
// the route name and namespace as formatted for the generated `Route` object in SwiftTypes.jinja
// Format: "<namespace>/<route_name>" e.g., "files/upload_session/append_v2" for Files.uploadSessionAppendV2
enum {{ class_name }}: ReconnectionHelpersShared {

    static func rebuildRequest(apiRequest: ApiRequest, client: DropboxTransportClientInternal) throws -> {{ return_type }} {
        let info = try persistedRequestInfo(from: apiRequest)

        switch info.namespaceRouteName {
        {% for route_args_data in background_compatible_namespace_route_pairs %}
            {% set namespace = route_args_data[0] %}
            {% set route = route_args_data[1] %}
            {% set args_data = route_args_data[2] %}
            case "{{ fmt_route_name_namespace(route, namespace.name) }}":
                return .{{ fmt_func_namespace(route.name, route.version, namespace.name) }}(
                    rebuildRequest(
                        apiRequest: apiRequest,
                        info: info,
                        route: {{ fmt_class(namespace.name) }}.{{ fmt_func(route.name, route.version) }},
                        client: client
                    )
                )
        {% endfor %}
            default:
                throw ReconnectionErrorKind.missingReconnectionCase
        }
    }
}

